Versions Compared

Key

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

While rule DCL50-CPP. Do not define a C-style variadic function forbids creation of such functions, they may still be defined when that function has external, C language linkage. Under these circumstances, care must be taken when invoking the va_start() macro. The C-standard library macro va_start() imposes several semantic restrictions on the type of the value of its second parameter. The C Standard, subclause 7.16.1.4, paragraph 4 [ISO/IEC 9899:2011], states the following:

The parameter parmN is the identifier of the rightmost parameter in the variable parameter list in the function definition (the one just before the ...). If the parameter parmN is declared with the register storage class, with a function or array type, or with a type that is not compatible with the type that results after application of the default argument promotions, the behavior is undefined.

...

Passing an object of an unsupported type as the second argument to va_start() can result in undefined behavior that might be exploited to cause data integrity violations.

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

EXP58-CPP

Medium

Unlikely

Medium

P4

L3e

L3

Automated Detection

Tool

Version

Checker

Description

Clang
Include Page
Clang_39_V
Clang_39_V
-WvarargsDoes not catch the violation in the third noncompliant code example (it is conditionally supported by Clang)
CodeSonar
Include Page
CodeSonar_V
CodeSonar_V

BADMACRO.STDARG_H

Use of <stdarg.h> Feature

Helix QAC

Include Page
Helix QAC_V
Helix QAC_V

C++3852, C++3853


Klocwork
Include Page
Klocwork_V
Klocwork_V
CERT.VA_START.TYPE
Parasoft C/C++test

Include Page
Parasoft_V
Parasoft_V

CERT_CPP-EXP58-a

Use macros for variable arguments correctly

Polyspace Bug Finder

Include Page
Polyspace Bug Finder_V
Polyspace Bug Finder_V

CERT C++: EXP58-CPPChecks for incorrect data types for second argument of va_start (rule fully covered)

Related Vulnerabilities

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

Related Guidelines

Bibliography

[ISO/IEC 9899:2011]Subclause 7.16.1.4, "The va_start Macro"
[ISO/IEC 14882-2014]Subclause 18.10, "Other Runtime Support"

...


...

Image Modified Image Modified Image Modified