Description
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.
Potential Impact
Availability, Integrity, Other
Other
Authorization, Other
Other
Demonstrative Examples
if (isset($_POST['names'])) {$nameArray = $_POST['names'];}echo "Hello " . $nameArray['first'];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);char *test_string;
if (i != err_val)
{
test_string = "Hello World!";
}
printf("%s", test_string);char *test_string = "Done at the beginning";
if (i != err_val)
{
test_string = "Hello World!";
}
printf("%s", test_string);char *test_string;
if (i != err_val)
{
test_string = "Hello World!";
}
else {
test_string = "Done on the other side!";
}
printf("%s", test_string);Mitigations & Prevention
Ensure that critical variables are initialized before first use [REF-1485].
Most compilers will complain about the use of uninitialized variables if warnings are turned on.
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.
Choose a language that is not susceptible to these issues.
Mitigating technologies such as safe string libraries and container abstractions could be introduced.
Detection Methods
- Fuzzing High — 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,
- Automated Static Analysis High — 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 sea
Real-World CVE Examples
| CVE ID | Description |
|---|---|
| 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), returni |
| 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. |
| CVE-2008-0081 | Uninitialized variable leads to code execution in popular desktop application. |
| CVE-2007-4682 | Crafted input triggers dereference of an uninitialized object pointer. |
| CVE-2007-3468 | Crafted audio file triggers crash when an uninitialized variable is used. |
| CVE-2007-2728 | Uninitialized random seed variable used. |
Related Weaknesses
Taxonomy Mappings
- CLASP: — Uninitialized variable
- 7 Pernicious Kingdoms: — Uninitialized Variable
- Software Fault Patterns: SFP1 — Glitch in computation
- SEI CERT Perl Coding Standard: DCL33-PL — Declare identifiers before using them
Frequently Asked Questions
What is CWE-457?
CWE-457 (Use of Uninitialized Variable) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Variant-level weakness. The code uses a variable that has not been initialized, leading to unpredictable or unintended results.
How can CWE-457 be exploited?
Attackers can exploit CWE-457 (Use of Uninitialized Variable) to other. This weakness is typically introduced during the Implementation phase of software development.
How do I prevent CWE-457?
Key mitigations include: Ensure that critical variables are initialized before first use [REF-1485].
What is the severity of CWE-457?
CWE-457 is classified as a Variant-level weakness (Low-Medium abstraction). It has been observed in 6 real-world CVEs.