...
Wiki Markup |
---|
According to C99 \[[ISO/IEC 9899:1999|AA. Bibliography#ISO/IEC 9899-1999]\]: |
The lifetime of an object is the portion of program execution during which storage is guaranteed to be reserved for it. An object exists, has a constant address, and retains its last-stored value throughout its lifetime. If an object is referred to outside of its lifetime, the behavior is undefined. The value of a pointer becomes indeterminate when the object it points to reaches the end of its lifetime.
Attempting to access an object outside of its lifetime can result in undefined behavior and lead to an exploitable vulnerability. (see See also undefined behavior 8 of Appendix J.).
Noncompliant Code Example (Static Variables)
...
Some compilers generate a warning when a pointer to an automatic variable is returned from a function, as in this example. Compile your code at high warning levels and resolve any warnings. (see See guideline MSC00-C. Compile cleanly at high warning levels.).
Compliant Solution (Return Values)
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
DCL30-C | high | probable | high | P6 | L2 |
Automated Detection
...
Tool | Version | Checker | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
|
|
| ||||||||
|
|
...
|
|
...
|
|
|
| ||||||||
|
...
|
|
|
| ||||
|
...
|
|
...
|
...
|
|
|
|
...
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Other Languages
Related Guidelines
This rule appears in the C++ Secure Coding Standard as : DCL30-CPP. Declare objects with appropriate storage durations.
Bibliography
Wiki Markup |
---|
\[[Coverity 072007|AA. Bibliography#Coverity 07]\] \[[ISO/IEC 9899:1999|AA. Bibliography#ISO/IEC 9899-1999]\] Section 6.2.4, "Storage durations of objects," and Section 7.20.3, "Memory management functions" \[[ISO/IEC PDTR 24772|AA. Bibliography#ISO/IEC PDTR 24772]\] "DCM Dangling references to stack frames" \[[MISRA 042004|AA. Bibliography#MISRA 04]\] Rule 8.6 |
...