Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Do not make any assumptions about the size of environment variables , because an adversary might have full control over the environment. If the environment variable needs to be stored, then the length of the associated string should be calculated, and the storage dynamically allocated. (see See rule STR31-C. Guarantee that storage for strings has sufficient space for character data and the NULL terminator.).

Noncompliant Code Example

...

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

ENV01-C

high

likely

medium

P18

L1

Automated Detection

Tool

Version

Checker

Description

Section

Compass/ROSE

 

 

Section

can detect violations of the rule by using the same method as rule STR31-C. Guarantee that storage for strings has sufficient space for character data and the null terminator

...

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

Other Languages

Related Guidelines

CERT This rule appears in the C++ Secure Coding Standard as : ENV01-CPP. Do not make assumptions about the size of an environment variable.

Bibliography

Wiki Markup\[[ISO/IEC 9899:1999|AA. Bibliography#ISO/IEC 9899-1999]\] Section 7.20.4, "Communication with the environment"

MITRE CWE: CWE-119, "Failure to Constrain Operations within the Bounds of an Allocated Memory Buffer"

Bibliography

Wiki Markup

\[[MITRE 07|AA. Bibliography#MITRE 07]\] [CWE ID 119|http://cwe.mitre.org/data/definitions/119.html], "Failure to Constrain Operations within the Bounds of an Allocated Memory Buffer"
\[[Open Group 042004|AA. Bibliography#Open Group 04]\] Chapter 8, "Environment Variables"
\[[Viega 032003|AA. Bibliography#Viega 03]\] Section 3.6, "Using Environment Variables Securely"

...