Skip to content

Use of stack variable with putenv

Description

The software calls putenv() with a variable that has a short lifetime, such as a pointer to an automatic variable allocated on the stack. This can lead to undefined behavior when the environment variable is accessed after the stack variable has gone out of scope.

Examples

Insecure Code

c
char buf[10]; putenv(buf);

Secure Code

c
putenv("STATIC_STRING");

Remediation

Call putenv() with a static or global string instead of a stack variable.

Rule Details

FieldValue
IDCODE-0269
CategoryInsecureConfig
SeverityMEDIUM
CWECWE-562
ConfidenceLOW
ImpactMEDIUM
LikelihoodMEDIUM
ExploitabilityMODERATE
Tagsputenv, stack variable
OWASPN/A

References