You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 50 Next »

If a file with the same name as a standard header is placed in the search path for included source files, the behavior is undefined.

The following table lists these standard headers:

<assert.h>

<complex.h>

<ctype.h>

<errno.h>

<fenv.h>

<float.h>

<inttypes.h>

<iso646.h>

<limits.h>

<locale.h>

<math.h>

<setjmp.h>

<signal.h>

<stdarg.h>

<stdbool.h>

<stddef.h>

<stdint.h>

<stdio.h>

<stdlib.h>

<string.h>

<tgmath.h>

<time.h>

<wchar.h>

<wctype.h>

Do not reuse standard header file names, system-specific header file names, or other header file names.

Noncompliant Code Example

In this noncompliant code example, the programmer chooses to use a local version of the standard library but does not make the change clear.

#include &quot;stdio.h&quot;  /* confusing, distinct from &lt;stdio.h&gt; */

/* ... */

Compliant Solution

The solution addresses the problem by giving the local library a unique name (as per PRE08-C. Guarantee that header file names are unique), which makes it apparent that the library used is not the original.

/* Using a local version of stdio.h */ 
#include &quot;mystdio.h&quot;

/* ... */

Risk Assessment

Using header file names that conflict with other header file names can result in an incorrect file being included.

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

PRE04-C

low

unlikely

medium

P2

L3

Automated Detection

The LDRA tool suite V 7.6.0 can detect violations of this recommendation.

Related Vulnerabilities

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

Other Languages

This rule appears in the C++ Secure Coding Standard as PRE04-CPP. Do not reuse a standard header file name.

References

[[ISO/IEC 9899:1999]] Section 7.1.2, "Standard Headers"


PRE03-C. Prefer typedefs to defines for encoding types&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;01. Preprocessor (PRE)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

  • No labels