1096
Strategy = Attack Surface Reduction
Assign all variables to an initial value.
Phase: Build and Compilation
Strategy = Compilation or Build Hardening
Most compilers will complain about the use of uninitialized variables if warnings are turned on.
Phase: Implementation
Phase: 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
The choice could be made to use 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.
Demonstrative Examples
Example 1:
This code prints a greeting using information stored in a POST request:
Example Language: PHP (Bad)
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.
Example 2:
The following switch statement is intended to set the values of the variables aN and bN before they
are used:
Example Language: C (Bad)
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;
CWE Version 4.14
CWE-457: Use of Uninitialized Variable
CWE-457: Use of Uninitialized Variable