...
DCL50-CPP-EX2: As stated in the normative text, C-style variadic functions that are declared but never defined are permitted. For example, when a function call expression appears in an unevaluated context, such as the argument in a sizeof expression, overload resolution is performed to determine the result type of the call but does not require a function definition. Some template metaprogramming techniques that employ SFINAE use variadic function declarations to implement compile-time type queries, as in the following example:.
| Code Block | ||||
|---|---|---|---|---|
| ||||
template <typename Ty>
class has_foo_function {
typedef char yes[1];
typedef char no[2];
template <typename Inner>
static yes& test(Inner *I, decltype(I->foo()) * = nullptr); // Function is never defined.
template <typename>
static no& test(...); // Function is never defined.
public:
static const bool value = sizeof(test<Ty>(nullptr)) == sizeof(yes);
}; |
...
Incorrectly using a variadic function can result in abnormal program termination, unintended information disclosure, or execution of arbitrary code.
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
|---|---|---|---|---|---|
DCL50-CPP | High | Probable | Medium | P12 | L1 |
Automated Detection
Tool | Version | Checker | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Astrée |
| function-ellipsis | Fully checked | ||||||
| Axivion Bauhaus Suite |
| CertC++-DCL50 | |||||||
| Clang |
| cert-dcl50-cpp | Checked by clang-tidy. | ||||||
| CodeSonar |
| LANG.STRUCT.ELLIPSIS
| Ellipsis | ||||||
| Helix QAC |
| C++2012, C++2625 | |||||||
| Klocwork |
| MISRA.FUNC.VARARG | |||||||
| LDRA tool suite |
| 41 S | Fully Implemented | ||||||
| Parasoft C/C++test |
| CERT_CPP-DCL50-a | Functions shall not be defined with a variable number of arguments | |||||||
| Polyspace Bug Finder |
| CERT C++: DCL50-CPP | Checks for function definition with ellipsis notation (rule fully covered) | ||||||
| RuleChecker |
| function-ellipsis | Fully checked |
2012
2625
| SonarQube C/C++ Plugin |
| FunctionEllipsis |
Related Vulnerabilities
Search for other vulnerabilities resulting from the violation of this rule on the CERT website.
Bibliography
...