Skip to content

Untrusted Input from getenv or curl_getenv

Description

The return value of getenv or curl_getenv should be treated as untrusted input as it could be modified by an attacker, potentially leading to buffer overflows, malicious file usage, or unauthorized file access.

Examples

Insecure Code

c
char *path = getenv("PATH");
system(path);

Secure Code

c
char *path = getenv("PATH");
if (path != NULL && strlen(path) < 1024) {
    // validate and sanitize path
    system(path);
}

Remediation

Validate and sanitize the return value of getenv or curl_getenv before using it in security decisions.

Rule Details

FieldValue
IDCODE-0566
CategoryInjection
SeverityHIGH
CWECWE-807
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityMODERATE
Tagsinjection, untrusted input
OWASPA1:2017-Injection, A03:2021-Injection