Versions Compared

Key

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

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.

These are the The following table from the C Standard, subclause 7.1.2 [ISO/IEC 9899:2011], lists these standard headers:

<assert.h>
<complex
<float.h><math.h>
<ctype
<stdatomic.h>
<errno
<stdlib.h>
<fenv
<time.h>
<float
<complex.h><inttypes.h><setjmp.h>
<iso646
<stdbool.h>
<limits
<stdnoreturn.h>
<locale
<uchar.h>
<math
<ctype.h>
<setjmp
<iso646.h><signal.h><stddef.h><string.h><wchar.h>
<stdarg
<errno.h>
<stdbool
<limits.h>
<stddef
<stdalign.h><stdint.h>
<stdio
<tgmath.h>
<stdlib
<wctype.h>
<string
<fenv.h>
<tgmath
<locale.h>
<time
<stdarg.h>
<wchar
<stdio.h>
<wctype
<threads.h>

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

...

Noncompliant Code Example

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

Code Block
bgColor#FFcccc
langc#ffcccc

#include "stdio.h"  /* confusingConfusing, distinct from <stdio.h> */

/* ... */

Compliant Solution

Wiki MarkupThe solution addresses the problem by giving the local library a unique name (as per \[[PRE08-AC. Guarantee that header file names are unique]\]) , which makes it explicit apparent that the library used is not the original.:

Code Block
bgColor#ccccFF
langc#ccccff

/* Using a local version of stdio.h */ 
#include "mystdio.h"

/* ... */

Risk Assessment

Using header file names that conflict with the C standard library functions other header file names can result in not including the intended filean incorrect file being included.

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

PRE04-

A

C

low

Low

unlikely

Unlikely

low

Medium

P3

P2

L3

Automated Detection

...

ToolVersionCheckerDescription
Axivion Bauhaus Suite

Include Page
Axivion Bauhaus Suite_V
Axivion Bauhaus Suite_V

CertC-PRE04

ECLAIR

Include Page
ECLAIR_V
ECLAIR_V

CC2.PRE04

Fully implemented

Helix QAC

Include Page
Helix QAC_V
Helix QAC_V

C5001
LDRA tool suite
Include Page
LDRA_V
LDRA_V

568 S

Fully implemented

Related Vulnerabilities

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

References

...

Related Guidelines

Bibliography

[ISO/IEC 9899:2011]Subclause

...

7.1.2,

...

"Standard

...

Headers"


...

PRE03-A. Prefer typedefs to defines for encoding types      01. Preprocessor (PRE)       PRE05-A. Understand macro replacement when concatenating tokens or performing stringificationImage Added Image Added Image Added