Versions Compared

Key

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

The variable parameters of a variadic function, that is, those that correspond with the position of the ellipsis, are interpreted by the va_arg() macro. The va_arg() macro is used to extract the next argument from an initialized argument list within the body of a variadic function implementation. The size of each parameter is determined by the specified type. If the type is inconsistent with the corresponding argument, the behavior is undefined and may result in misinterpreted data or an alignment error. (see See guideline EXP36-C. Do not convert pointers into more strictly aligned pointer types.).

The variable arguments to a variadic function are not checked for type by the compiler.   As a result, the programmer is responsible for ensuring that they are compatible with the corresponding parameter after the default argument promotions:

...

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

DCL11-C

high

probable

high

P6

L2

Automated Detection

...

Tool

Version

Checker

Description

Section

GCC

Include Page
c:GCC_V
c:GCC_V

 

Section

warns about inconsistently typed arguments to formatted output functions when the -Wall is used

...

Section

Compass/ROSE

...

 

 

Section

does NOT currently detect violations of this recommendation. While the recommendation in general cannot be automated, due to the difficulty in enforcing contracts between a variadic function and its invokers, it would be fairly easy to enforce type correctness on arguments to the printf() family of functions.

Related Vulnerabilities

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

...

Wiki Markup
\[[ISO/IEC 9899:1999|AA. Bibliography#ISO/IEC 9899-1999]\] Section 6.5.2.2, "Function calls," and Section 7.15, "Variable arguments"
\[[ISO/IEC PDTR 24772|AA. Bibliography#ISO/IEC PDTR 24772]\] "IHN Type system" and "OTR Subprogram Signature Mismatch"
\[[MISRA 042004|AA. Bibliography#MISRA 04]\] Rule 16.1

...