Call to setenv or putenv family function
modifies environment pointed to by pointer
This defect occurs when you use the third argument of main() in a hosted environment to access the environment after an operation modifies the environment. In a hosted environment, many C implementations support the nonstandard syntax:
main (int argc, char *argv[], char *envp[])
setenv or putenv family function
modifies the environment pointed to by *envp.When you modify the environment through a call to a setenv or
putenv family function, the environment memory can
potentially be reallocated. The hosted environment pointer is not updated and might
point to an incorrect location. A call to this pointer can return unexpected results
or cause an abnormal program termination.
Do not use the hosted environment pointer. Instead, use global external variable
environ in Linux®, _environ or _wenviron in
Windows®, or their equivalent. When you modify the environment, these variables
are updated.
| Group: Programming |
| Language: C | C++ |
| Default: On for handwritten code, off for generated code |
Command-Line Syntax:
INVALID_ENV_POINTER |
| Impact: Medium |
| CWE ID: 825 |
Find defects (-checkers) | Misuse of return value from nonreentrant standard
function | Modification of internal buffer returned from
nonreentrant standard function