Local, automatic variables can assume unexpected values if they are used before they are initialized. C99 specifies "If an object that has automatic storage duration is not initialized explicitly, its value is indeterminate" [[ISO/IEC 9899-1999]]. In practice, this value defaults to whichever values are currently stored in stack memory. While uninitialized memory often contains zero, this is not guaranteed. Consequently, uninitialized memory can cause a program to behave in an unpredictable or unplanned manner and may provide an avenue for attack.
In most cases compilers warn about uninitialized variables. These warnings should be handled appropriately by the programmer as stated in MSC00-A. Compile cleanly at high warning levels.
Risk Assessment
Accessing uninitialized variables generally leads to unexpected program behavior. In some cases this includes the execution of arbitrary code.
Rule |
Severity |
Likelihood |
Remediation Cost |
Priority |
Level |
---|---|---|---|---|---|
EXP04-A |
1 (low) |
1 (unlikely) |
2 (medium) |
P2 |
L3 |
References
[[mercy]]
[[ISO/IEC 9899-1999]] Section 6.7.8, "Initialization"
[Halvar]