CWE-457

Variant Abstraction Level
Pillar — Highest-level weakness category
Class — Abstract, language-independent
Base — Specific enough to detect
Variant — Tied to specific technology
Compound — Requires multiple weaknesses
Draft MITRE CWE Status
Stable — Fully reviewed and complete
Draft — Under development, may change
Incomplete — Partially defined by MITRE
Deprecated — No longer recommended
Obsolete — Replaced by another CWE
Exploit: High
Use of Uninitialized Variable

Description

The code uses a variable that has not been initialized, leading to unpredictable or unintended results.

Top Monitored CVEs

Consequences

Confidentiality, Integrity, Availability, Other — Varies by Context, Read Application Data

Uninitialized variables usually contain junk, which can not be trusted for consistency. Depending on the context, uninitialized variables could lead to denial of service conditions, or modify control flow in unexpected ways. They could also contain sensitive information that could be leaked if the variable is used in output. In some cases, an attacker can "pre-initialize" the variable using previous actions - i.e., control the contents of the variable - which might enable code execution.

Availability — Alter Execution Logic, Unexpected State

This can cause a race condition if a lock variable check passes when it should not.

Authorization, Other — Varies by Context

Strings that are not initialized are especially dangerous, since many functions expect a null at the end -- and only at the end -- of a string.

Mitigations

Phase: Implementation

Ensure that critical variables are initialized before first use [REF-1485].

Phase: Build and Compilation

Most compilers will complain about the use of uninitialized variables if warnings are turned on.

Phase: Implementation, Operation

When using a language that does not require explicit declaration of variables, run or compile the software in a mode that reports undeclared or unknown variables. This may indicate the presence of a typographic error in the variable's name.

Phase: Requirements

Choose a language that is not susceptible to these issues.

Phase: Architecture and Design

Mitigating technologies such as safe string libraries and container abstractions could be introduced.

Detection

Fuzzing

Fuzz testing (fuzzing) is a powerful technique for generating large numbers of diverse inputs - either randomly or algorithmically - and dynamically invoking the code with those inputs. Even with random inputs, it is often capable of generating unexpected results such as crashes, memory corruption, or resource consumption. Fuzzing effectively produces repeatable test cases that clearly indicate bugs, which helps developers to diagnose the issues.

Automated Static Analysis

Automated 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.)