| Wiki Markup |
|---|
C99 \[[ISO/IEC 9899:1999|AA. Bibliography#ISO/IEC 9899-1999]\] Section 6.5.2.2 says (see also [undefined behavior 35 | CC. Undefined Behavior#ub_35] of Annex J): |
If an attempt is made to modify the result of a function call or to access it after the next sequence point, the behavior is undefined.
(See also undefined behavior 35 of Annex J.)
C functions may not return arrays; however, they may return structs or unions that contain arrays.
...
- In C, the lifetime of a return value ends at the next sequence point. Consequently by the time
printf()is called, thestructreturned by theaddressee()call is no longer considered valid, and may have been overwritten. - C function arguments are passed by value. As a result, copies are made of all objects generated by the arguments. For example, a copy is made of the pointer to
"Hello, %s!\n". Under most circumstances, these copies protect you from the effects of sequence points described earlier. - Finally, C implicitly converts arrays to pointers when passing them as function arguments. This means that a copy is made of the pointer to the
addresee().aarray, and that pointer copy is passed toprintf(). But the array data itself is not copied , and may no longer exist whenprintf()is called.
Consequently, when printf() tries to dereference the pointer passed as its 2nd argument, it is likely to find garbage.
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
|---|---|---|---|---|---|
EXP35-C | low | probable | medium | P4 | L3 |
Automated Detection
Splint Version 3.1.1 can detect violations of this rule.
...
Tool | Version | Checker | Description | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
|
| ||||||||||
|
|
|
|
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
...