The code uses a variable that has not been initialized, leading to unpredictable or unintended results.
In some languages such as C and C++, stack variables are not initialized by default. They generally contain junk data with the contents of stack memory before the function was invoked. An attacker can sometimes control or read these contents. In other languages or conditions, a variable that is not explicitly initialized can be given a default value that has security implications, depending on the logic of the program. The presence of an uninitialized variable can sometimes indicate a typographic error in the code.

Primary

Implementation
In C, using an uninitialized char * in some string libraries will return incorrect results, as the libraries expect the null terminator to always be at the end of a string, even if the string is empty.

High

Availability
Integrity
Other
Other
Initial variables usually contain junk, which can not be trusted for consistency. This can lead to denial of service conditions, or modify control flow in unexpected ways. In some cases, an attacker can "pre-initialize" the variable using previous actions, which might enable code execution. This can cause a race condition if a lock variable check passes when it should not.

Authorization
Other
Other
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.

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.
High

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

Implementation
Attack Surface Reduction
Ensure that critical variables are initialized before first use [REF-1485].

Build and Compilation
Compilation or Build Hardening
Most compilers will complain about the use of uninitialized variables if warnings are turned on.

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.

Requirements
Language Selection
Choose a language that is not susceptible to these issues.

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

This code prints a greeting using information stored in a POST request:

if (isset($_POST['names'])) {$nameArray = $_POST['names'];}echo "Hello " . $nameArray['first'];

This code checks if the POST array 'names' is set before assigning it to the $nameArray variable. However, if the array is not in the POST request, $nameArray will remain uninitialized. This will cause an error when the array is accessed to print the greeting message, which could lead to further exploit.

The following switch statement is intended to set the values of the variables aN and bN before they are used:

int aN, Bn;switch (ctl) {
case -1:aN = 0;bN = 0;break;
case 0:aN = i;bN = -i;break;
case 1:aN = i + NEXT_SZ;bN = i - NEXT_SZ;break;
default:aN = -1;aN = -1;break;

}repaint(aN, bN);

In the default case of the switch statement, the programmer has accidentally set the value of aN twice. As a result, bN will have an undefined value. Most uninitialized variable issues result in general software reliability problems, but if attackers can intentionally trigger the use of an uninitialized variable, they might be able to launch a denial of service attack by crashing the program. Under the right circumstances, an attacker may be able to control the value of an uninitialized variable by affecting the values on the stack prior to the invocation of the function.

This example will leave test_string in an
unknown condition when i is the same value as err_val,
because test_string is not initialized
(CWE-456). Depending on where this code segment appears
(e.g. within a function body), test_string might be
random if it is stored on the heap or stack. If the
variable is declared in static memory, it might be zero
or NULL. Compiler optimization might contribute to the
unpredictability of this address.

char *test_string;
if (i != err_val)
{
test_string = "Hello World!";
}
printf("%s", test_string);

When the printf() is reached,
test_string might be an unexpected address, so the
printf might print junk strings (CWE-457).

To fix this code, there are a couple approaches to
making sure that test_string has been properly set once
it reaches the printf().
One solution would be to set test_string to an
acceptable default before the conditional:

char *test_string = "Done at the beginning";
if (i != err_val)
{
test_string = "Hello World!";
}
printf("%s", test_string);

Another solution is to ensure that each
branch of the conditional - including the default/else
branch - could ensure that test_string is set:

char *test_string;
if (i != err_val)
{
test_string = "Hello World!";
}
else {
test_string = "Done on the other side!";
}
printf("%s", test_string);

CVE-2019-15900
Chain: sscanf() call is used to check if a username and group exists, but the return value of sscanf() call is not checked (CWE-252), causing an uninitialized variable to be checked (CWE-457), returning success to allow authorization bypass for executing a privileged (CWE-863).
https://www.cve.org/CVERecord?id=CVE-2019-15900

CVE-2008-3688
Chain: A denial of service may be caused by an uninitialized variable (CWE-457) allowing an infinite loop (CWE-835) resulting from a connection to an unresponsive server.
https://www.cve.org/CVERecord?id=CVE-2008-3688

CVE-2008-0081
Uninitialized variable leads to code execution in popular desktop application.
https://www.cve.org/CVERecord?id=CVE-2008-0081

CVE-2007-4682
Crafted input triggers dereference of an uninitialized object pointer.
https://www.cve.org/CVERecord?id=CVE-2007-4682

CVE-2007-3468
Crafted audio file triggers crash when an uninitialized variable is used.
https://www.cve.org/CVERecord?id=CVE-2007-3468

CVE-2007-2728
Uninitialized random seed variable used.
https://www.cve.org/CVERecord?id=CVE-2007-2728

Uninitialized variable

Uninitialized Variable

SFP1
Glitch in computation

DCL33-PL
Declare identifiers before using them
Imprecise

Allowed
This CWE entry is at the Variant level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.
Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction.

CLASP
2006-07-19
Draft 3
2006-07-19

Eric Dalci
Cigital
2008-07-01
updated Time_of_Introduction

KDM Analytics
2008-08-01
added/updated white box definitions

CWE Content Team
MITRE
2008-09-08
updated Applicable_Platforms, Common_Consequences, Description, Relationships, Observed_Example, Other_Notes, References, Taxonomy_Mappings

CWE Content Team
MITRE
2009-01-12
updated Common_Consequences, Demonstrative_Examples, Potential_Mitigations

CWE Content Team
MITRE
2009-03-10
updated Demonstrative_Examples

CWE Content Team
MITRE
2009-05-27
updated Demonstrative_Examples

CWE Content Team
MITRE
2011-06-01
updated Common_Consequences

CWE Content Team
MITRE
2012-05-11
updated References, Relationships

CWE Content Team
MITRE
2012-10-30
updated Demonstrative_Examples

CWE Content Team
MITRE
2013-02-21
updated Applicable_Platforms, Description, Other_Notes, Potential_Mitigations, Relationships

CWE Content Team
MITRE
2014-06-23
updated Modes_of_Introduction, Other_Notes

CWE Content Team
MITRE
2014-07-30
updated Relationships, Taxonomy_Mappings

CWE Content Team
MITRE
2017-11-08
updated References, Relationships, Taxonomy_Mappings, White_Box_Definitions

CWE Content Team
MITRE
2019-01-03
updated Taxonomy_Mappings

CWE Content Team
MITRE
2019-06-20
updated Relationships, Type

CWE Content Team
MITRE
2020-02-24
updated References, Relationships, Type

CWE Content Team
MITRE
2020-08-20
updated Relationships

CWE Content Team
MITRE
2020-12-10
updated Relationships

CWE Content Team
MITRE
2021-03-15
updated Demonstrative_Examples, Observed_Examples, Relationships

CWE Content Team
MITRE
2021-07-20
updated Observed_Examples

CWE Content Team
MITRE
2023-04-27
updated Detection_Factors, References, Relationships

CWE Content Team
MITRE
2023-06-29
updated Mapping_Notes

CWE Content Team
MITRE
2025-09-09
4.18
2025-09-09
updated Potential_Mitigations, References

CWE Content Team
MITRE
2025-12-11
4.19
2025-12-11
updated Weakness_Ordinalities

Uninitialized Variable