CWE-665: Improper Initialization

What is CWE-665?

The product fails to initialize a resource correctly, leaving it in an unexpected state when the resource is accessed or used.

Data statistics

RELATED CVES (365 DAYS)10
ABSTRACTIONClass
LIKELIHOOD OF EXPLOITMedium

Vulnerabilities mapped to CWE-665

10 vulnerabilities233.3% increase year over year

Vulnerabilities in CISA KEV for CWE-665

0 vulnerabilities

Official definition

ByMitre CWE

The product does not initialize or incorrectly initializes a resource, which might leave the resource in an unexpected state when it is accessed or used.

This can have security implications when the associated resource is expected to have certain properties or values, such as a variable that determines whether a user has been authenticated or not.

Detailed description

An uninitialized resource may contain leftover or indeterminate data while the program assumes that it has safe, valid properties. This is especially significant when the resource is an authentication state, access-control flag, reused memory, array index, pointer, or handler. The weakness can arise on rare error paths, when complex control flow skips initialization, or when another thread accesses the resource before initialization is complete.

Characteristics

This weakness occurs when a variable, resource, or data region is accessed before it has a valid state, or when initialization occurs only on some control-flow paths. Rarely exercised paths, especially error handling and exception paths, are common locations for the problem. The resulting behavior depends on the residual or unintended value, which may be interpreted as a security decision, an index, a pointer, a function handler, or data sent to an external party.

Common consequences

Potential impacts include disclosure of residual memory or application data when reused resources are exposed to an untrusted party. If a security-critical decision depends on a value being zero or equivalent, an unintended value can bypass a protection mechanism. Unexpected values can also alter program flow, causing crashes, exits, restarts, incorrect results, memory corruption, or code execution in representative cases.

ImpactScopeExplanation
Read Memory, Read Application DataConfidentialityWhen reusing a resource such as memory or a program variable, the original contents of that resource may not be cleared before it is sent to an untrusted party.
Bypass Protection MechanismAccess ControlIf security-critical decisions rely on a variable having a "0" or equivalent value, and the programming language performs this initialization on behalf of the programmer, then a bypass of security may occur.
DoS: Crash, Exit, or RestartAvailabilityThe uninitialized data may contain values that cause program flow to change in ways that the programmer did not intend. For example, if an uninitialized variable is used as an array index in C, then its previous contents may produce an index that is outside the range of the array, possibly causing a crash or an exit in other environments.

Risk mitigations

Use a language that prevents uninitialized data or makes it easier to avoid, for example through compile-time checks or defined default values. At the architecture and design stage, identify variables and data stores receiving external information and validate inputs so they are initialized only to expected values. Explicitly initialize every variable and data store at declaration or immediately before first use, and review complex conditionals to ensure that every relevant path performs initialization. Avoid race conditions during initialization routines, and compile or build the product with settings that warn about uninitialized variables or data.

  1. Language Selection · RequirementsUse a language that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid. For example, in Java, if the programmer does not explicitly initialize a variable, then the code could produce a compile-time error (if the variable is local) or automatically initialize the variable to the default value for the variable's type. In Perl, if explicit initialization is not performed, then a default value of undef is assigned, which is interpreted as 0, false, or an equivalent value depending on the context in which the variable is accessed.
  2. Architecture and DesignIdentify all variables and data stores that receive information from external sources, and apply input validation to make sure that they are only initialized to expected values.
  3. ImplementationExplicitly initialize all your variables and other data stores, either during declaration or just before the first usage.
  4. ImplementationPay close attention to complex conditionals that affect initialization, since some conditions might not perform the initialization.
  5. ImplementationAvoid race conditions (CWE-362) during initialization routines.
  6. Build and CompilationRun or compile your product with settings that generate warnings about uninitialized variables or data.

Detection methods

Automated static analysis, commonly implemented as Static Application Security Testing, can identify some instances by modeling data flow and control flow and looking for potentially vulnerable source-to-sink patterns. Automated dynamic analysis can use fuzzing, robustness testing, fault injection, and stress tests with many simultaneous threads or processes; unexpected instability, crashes, or incorrect results are indicators, with moderate effectiveness and possible blind spots in rarely executed paths. Manual dynamic analysis should trigger uncommon error conditions, such as low memory, insufficient privileges, interrupted transactions, or disabled basic network services, and monitor for unexpected behavior. An exception handled by the surrounding environment may still indicate that the application failed to handle the underlying condition itself.

MethodApproachEffectiveness
Automated Dynamic AnalysisThis weakness can be detected using dynamic tools and techniques that interact with the software using large test suites with many diverse inputs, such as fuzz testing (fuzzing), robustness testing, and fault injection. The software's operation may slow down, but it should not become unstable, crash, or generate incorrect results. Initialization problems may be detected with a stress-test by calling the software simultaneously from a large number of threads or processes, and look for evidence of any unexpected behavior. The software's operation may slow down, but it should not become unstable, crash, or generate incorrect results.Moderate
Manual Dynamic AnalysisIdentify error conditions that are not likely to occur during normal usage and trigger them. For example, run the program under low memory conditions, run with insufficient privileges or permissions, interrupt a transaction before it is completed, or disable connectivity to basic network services such as DNS. Monitor the software for any unexpected behavior. If you trigger an unhandled exception or similar error that was discovered and handled by the application's environment, it may still indicate unexpected conditions that were not handled by the application itself.—
Automated Static AnalysisAutomated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)High

Representative vulnerabilities

The following are representative examples, not an exhaustive list:

  • CVE-2001-1471: an invalid value prevents a library file from being included, skipping initialization of key variables and leading to eval injection.
  • CVE-2008-3637: improper error checking in a protection mechanism produces an uninitialized variable, enabling a security bypass and code execution.
  • CVE-2008-4197 and CVE-2008-0081: use of uninitialized memory or a variable can lead to code execution.
  • CVE-2008-2934, CVE-2008-0062, CVE-2009-2692, CVE-2009-0949, and CVE-2009-3620: initialization failures involving pointers, handlers, or data structures lead to crashes, null pointer dereferences, or double-free behavior.
  • CVE-2007-3749 and CVE-2005-1036: state or structures are not reset or initialized correctly, resulting in unauthorized access or privilege gain.
  • CVE-2008-0063: memory contents are not cleared while generating an error message, causing information leakage.
  • CVE-2008-3688, CVE-2008-3475, and CVE-2008-3597: improper initialization leads to an infinite loop, memory corruption, or access to structures before initialization has completed.
  • CVE-2008-5021: a race condition permits an object to be modified while it is still being initialized, causing the software to access uninitialized memory.

Below are representative vulnerabilities related to this CWE, prioritized by severity.

Sources (4)

CWE™ Program, operated by The MITRE Corporation. Copyright © 2006–2026, The MITRE Corporation. The MITRE Corporation hereby grants you a non-exclusive, royalty-free license to use CWE for research, development, and commercial purposes. CWE Terms of Use.

Learn more

Run an in-depth assessment with complete web risk management

CyStack VulnScan continuously discovers assets, validates vulnerabilities, and helps security teams prioritize remediation across the organization.

Explore CyStack VulnScan