| Impact | Details |
|---|---|
|
Other |
Scope: Availability, Integrity, 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.
|
|
Other |
Scope: Authorization, 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.
|
| Phase(s) | Mitigation |
|---|---|
|
Implementation |
Strategy: Attack Surface Reduction Ensure that critical variables are initialized before first use [REF-1485].
|
|
Build and Compilation |
Strategy: 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 |
Strategy: 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.
|
| Nature | Type | ID | Name |
|---|---|---|---|
| ChildOf | Base Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource. | 908 | Use of Uninitialized Resource |
| CanFollow | Variant Variant - a weakness that is linked to a certain type of product, typically involving a specific language or technology. More specific than a Base weakness. Variant level weaknesses typically describe issues in terms of 3 to 5 of the following dimensions: behavior, property, technology, language, and resource. | 456 | Missing Initialization of a Variable |
| Nature | Type | ID | Name |
|---|---|---|---|
| ChildOf | Class Class - a weakness that is described in a very abstract fashion, typically independent of any specific language or technology. More specific than a Pillar Weakness, but more general than a Base Weakness. Class level weaknesses typically describe issues in terms of 1 or 2 of the following dimensions: behavior, property, and resource. | 665 | Improper Initialization |
| Nature | Type | ID | Name |
|---|---|---|---|
| ChildOf | Class Class - a weakness that is described in a very abstract fashion, typically independent of any specific language or technology. More specific than a Pillar Weakness, but more general than a Base Weakness. Class level weaknesses typically describe issues in terms of 1 or 2 of the following dimensions: behavior, property, and resource. | 665 | Improper Initialization |
| Phase | Note |
|---|---|
| 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. |
C (Sometimes Prevalent)
C++ (Sometimes Prevalent)
Perl (Often Prevalent)
PHP (Often Prevalent)
Class: Not Language-Specific (Undetermined Prevalence)
Example 1
This code prints a greeting using information stored in a POST request:
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.
Example 2
The following switch statement is intended to set the values of the variables aN and bN before they are used:
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.
Example 3
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.
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:
Another solution is to ensure that each branch of the conditional - including the default/else branch - could ensure that test_string is set:
Note: this is a curated list of examples for users to understand the variety of ways in which this weakness can be introduced. It is not a complete list of all CVEs that are related to this CWE entry.
| Reference | Description |
|---|---|
|
Uninitialized variable leads to code execution in popular desktop application.
|
|
|
Crafted input triggers dereference of an uninitialized object pointer.
|
|
|
Crafted audio file triggers crash when an uninitialized variable is used.
|
|
|
Uninitialized random seed variable used.
|
| Method | Details |
|---|---|
|
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.
Effectiveness: 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.)
Effectiveness: High |
| Nature | Type | ID | Name |
|---|---|---|---|
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 398 | 7PK - Code Quality |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 998 | SFP Secondary Cluster: Glitch in Computation |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1180 | SEI CERT Perl Coding Standard - Guidelines 02. Declarations and Initialization (DCL) |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1416 | Comprehensive Categorization: Resource Lifecycle Management |
Rationale
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.Comments
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.| Mapped Taxonomy Name | Node ID | Fit | Mapped Node Name |
|---|---|---|---|
| CLASP | Uninitialized variable | ||
| 7 Pernicious Kingdoms | Uninitialized Variable | ||
| Software Fault Patterns | SFP1 | Glitch in computation | |
| SEI CERT Perl Coding Standard | DCL33-PL | Imprecise | Declare identifiers before using them |
| Submissions | |||
|---|---|---|---|
| Submission Date | Submitter | Organization | |
|
2006年07月19日
(CWE Draft 3, 2006年07月19日) |
CLASP | ||
| Modifications | |||
| Modification Date | Modifier | Organization | |
|
2025年09月09日
(CWE 4.18, 2025年09月09日) |
CWE Content Team | MITRE | |
| updated Potential_Mitigations, References | |||
| 2023年06月29日 | CWE Content Team | MITRE | |
| updated Mapping_Notes | |||
| 2023年04月27日 | CWE Content Team | MITRE | |
| updated Detection_Factors, References, Relationships | |||
| 2021年07月20日 | CWE Content Team | MITRE | |
| updated Observed_Examples | |||
| 2021年03月15日 | CWE Content Team | MITRE | |
| updated Demonstrative_Examples, Observed_Examples, Relationships | |||
| 2020年12月10日 | CWE Content Team | MITRE | |
| updated Relationships | |||
| 2020年08月20日 | CWE Content Team | MITRE | |
| updated Relationships | |||
| 2020年02月24日 | CWE Content Team | MITRE | |
| updated References, Relationships, Type | |||
| 2019年06月20日 | CWE Content Team | MITRE | |
| updated Relationships, Type | |||
| 2019年01月03日 | CWE Content Team | MITRE | |
| updated Taxonomy_Mappings | |||
| 2017年11月08日 | CWE Content Team | MITRE | |
| updated References, Relationships, Taxonomy_Mappings, White_Box_Definitions | |||
| 2014年07月30日 | CWE Content Team | MITRE | |
| updated Relationships, Taxonomy_Mappings | |||
| 2014年06月23日 | CWE Content Team | MITRE | |
| updated Modes_of_Introduction, Other_Notes | |||
| 2013年02月21日 | CWE Content Team | MITRE | |
| updated Applicable_Platforms, Description, Other_Notes, Potential_Mitigations, Relationships | |||
| 2012年10月30日 | CWE Content Team | MITRE | |
| updated Demonstrative_Examples | |||
| 2012年05月11日 | CWE Content Team | MITRE | |
| updated References, Relationships | |||
| 2011年06月01日 | CWE Content Team | MITRE | |
| updated Common_Consequences | |||
| 2009年05月27日 | CWE Content Team | MITRE | |
| updated Demonstrative_Examples | |||
| 2009年03月10日 | CWE Content Team | MITRE | |
| updated Demonstrative_Examples | |||
| 2009年01月12日 | CWE Content Team | MITRE | |
| updated Common_Consequences, Demonstrative_Examples, Potential_Mitigations | |||
| 2008年09月08日 | CWE Content Team | MITRE | |
| updated Applicable_Platforms, Common_Consequences, Description, Relationships, Observed_Example, Other_Notes, References, Taxonomy_Mappings | |||
| 2008年08月01日 | KDM Analytics | ||
| added/updated white box definitions | |||
| 2008年07月01日 | Eric Dalci | Cigital | |
| updated Time_of_Introduction | |||
| Previous Entry Names | |||
| Change Date | Previous Entry Name | ||
| 2008年04月11日 | Uninitialized Variable | ||
Use of the Common Weakness Enumeration (CWE™) and the associated references from this website are subject to the Terms of Use. CWE is sponsored by the U.S. Department of Homeland Security (DHS) Cybersecurity and Infrastructure Security Agency (CISA) and managed by the Homeland Security Systems Engineering and Development Institute (HSSEDI) which is operated by The MITRE Corporation (MITRE). Copyright © 2006–2025, The MITRE Corporation. CWE, CWSS, CWRAF, and the CWE logo are trademarks of The MITRE Corporation.