...
Note that C23, section 7.16.1.1, paragraph 2 indicates that it is safe to specify a signed integer conversion specifier with an unsigned integer argument, or an unsigned specifier with a signed argument, as long as both types are compatible , and the integer value is representable in both types. In contrast, the %n specifier requires a pointer to signed int, it is undefined behavior to pass it . Passing the %n specifier an unsigned int or any other type of integer is undefined behavior.
Format strings are usually string literals specified at the call site, but they need not be. However, they should not contain tainted values. (See FIO30-C. Exclude user input from format strings for more information.)
...
Rule | Severity | Likelihood | Detectable | Repairable | Priority | Level |
|---|---|---|---|---|---|---|
FIO47-C | High | Unlikely | Yes | No | P6 | L2 |
Automated Detection
Tool | Version | Checker | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Astrée |
| format-string-excessive-arguments format-string-mismatched-arguments invalid-format-string | Partially checked | ||||||
| Axivion Bauhaus Suite |
| CertC-FIO47 | Fully implemented | ||||||
| CodeSonar |
| IO.INJ.FMT | Format string injection | ||||||
| Coverity |
| PW | Reports when the number of arguments differs from the number of required arguments according to the format string | ||||||
| Cppcheck | | invalidscanf wrongPrintfScanfArgNum invalidLengthModifierError invalidScanfFormatWidth wrongPrintfScanfParameterPositionError | |||||||
| Cppcheck Premium |
| invalidscanf wrongPrintfScanfArgNum invalidLengthModifierError invalidScanfFormatWidth wrongPrintfScanfParameterPositionError | |||||||
| GCC |
| Can detect violations of this recommendation when the | |||||||
| Helix QAC |
| C0161, C0162, C0163, C0164, C0165, C0166, C0167, C0168, C0169, C0170, C0171, C0172, C0173, C0174, C0175, C0176, C0177, C0178, C0179, C0180, C0184, C0185, C0190, C0191, C0192, C0193, C0194, C0195, C0196, C0197, C0198, C0199, C0200, C0201, C0202, C0204, C0206, C0209 C++3150, C++3151, C++3152, C++3153, C++3154, C++3155, C++3156, C++3157, C++3158, C++3159 | |||||||
| Klocwork |
| SV.FMT_STR.PRINT_FORMAT_MISMATCH.BAD | |||||||
| LDRA tool suite |
| 486 S | Fully implemented | ||||||
| Parasoft C/C++test |
| CERT_C-FIO47-a | There should be no mismatch between the '%s' and '%c' format specifiers in the format string and their corresponding arguments in the invocation of a string formatting function | ||||||
| PC-lint Plus |
| 492, 493, 494, 499, 557, | Fully supported | ||||||
| Polyspace Bug Finder |
| CERT C: Rule FIO47-C | Check for format string specifiers and arguments mismatch (rule fully covered) | ||||||
| PVS-Studio |
| V510, V576 | |||||||
| RuleChecker |
| format-string-excessive-arguments | Partially checked | ||||||
| Security Reviewer - Static Reviewer |
| C81 C82 C83 C83 C84 C85 C86 C86 | |||||||
| TrustInSoft Analyzer |
| match format and arguments | Exhaustively verified (see the compliant and the non-compliant example). |
...