...
This compliant solution modifies the format string so that the conversion specifiers correspond to the arguments.:
Code Block | ||||
---|---|---|---|---|
| ||||
const char *error_msg = "Error occurred"; /* ... */ printf("%d:%s", 15, error_msg); |
...
This compliant solution adds the length modifier ll
to the %d
format specifier so that the variadic function parser for printf()
extracts the correct number of bytes from the variable argument list for the long long
argument.:
Code Block | ||||
---|---|---|---|---|
| ||||
long long a = 1; const char msg[] = "Default message"; /* ... */ printf("%lld %s", a, msg); |
...
This compliant solution avoids sending NULL
to printf()
.:
Code Block | ||||
---|---|---|---|---|
| ||||
char* string = NULL; printf("%s %d\n", (string ? string : "null"), 1); |
...
Tool | Version | Checker | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
Compass/ROSE |
|
| Does not currently detect violations of this recommendation. Although the recommendation in general cannot be automated, because of 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 | ||||||
| callfmt | Partially implemented. | |||||||
GCC |
|
| Warns about inconsistently typed arguments to formatted output functions when the | ||||||
| 41 S | Partially implemented. | |||||||
PRQA QA-C |
| 0179 (U) | Partially implemented. |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this recommendation on the CERT website.
...
ISO/IEC TR 24772:2013 | Type System [IHN] Subprogram Signature Mismatch [OTR] |
MISRA - C:2012 | Rule 1617.1 (required) |
...