Versions Compared

Key

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

...

Valid and meaningful combinations are marked by the (tick) symbol (save for the length modifier columns, as described previously). Valid combinations that have no effect are labeled N/E. Using a combination marked by the (error) symbol, using a specification not represented in the table, or using an argument of an unexpected type is undefined behavior. (See undefined behaviors 153, 155, 157, 158, 161, and 162.) 

Conversion
Specifier
Character

' XSI

-
+
SPACE


#


0


h


hh


l


ll


j


z


t


L

Argument
Type

d, i

(tick)

(tick)

(error)

(tick)

short

signed char

long

long long

intmax_t

size_t

ptrdiff_t

(error)

Signed integer

o

(error)

(tick)

(tick)

(tick)

unsigned short

unsigned char

unsigned long

unsigned long long

uintmax_t

size_t

ptrdiff_t

(error)

Unsigned integer

u

(tick)

(tick)

(error)

(tick)

unsigned short

unsigned  char

unsigned long

unsigned long long

uintmax_t

size_t

ptrdiff_t

(error)

Unsigned integer

x, X

(error)

(tick)

(tick)

(tick)

unsigned short

unsigned char

unsigned long

unsigned long long

uintmax_t

size_t

ptrdiff_t

(error)

Unsigned integer

f, F

(tick)

(tick)

(tick)

(tick)

(error)

(error)

N/E

N/E

(error)

(error)

(error)

long double

double or long double

e, E

(error)

(tick)

(tick)

(tick)

(error)

(error)

N/E

N/E

(error)

(error)

(error)

long double

double or long double

g, G

(tick)

(tick)

(tick)

(tick)

(error)

(error)

N/E

N/E

(error)

(error)

(error)

long double

double or long double

a, A

(tick)

(tick)

(tick)

(tick)

(error)

(error)

N/E

N/E

(error)

(error)

(error)

long double

double or long double

c

(error)

(tick)

(error)

(error)

(error)

(error)

wint_t

(error)

(error)

(error)

(error)

(error)

int or wint_t

s

(error)

(tick)

(error)

(error)

(error)

(error)

NTWS

(error)

(error)

(error)

(error)

(error)

NTBS or NTWS

p

(error)

(tick)

(error)

(error)

(error)

(error)

(error)

(error)

(error)

(error)

(error)

(error)

void*

n

(error)

(tick)

(error)

(error)

short*

char*

long*

long long*

intmax_t*

size_t*

ptrdiff_t*

(error)

Pointer to integer

C XSI

(error)

(tick)

(error)

(error)

(error)

(error)

(error)

(error)

(error)

(error)

(error)

(error)

wint_t

S XSI

(error)

(tick)

(error)

(error)

(error)

(error)

(error)

(error)

(error)

(error)

(error)

(error)

NTWS

%

(error)

(tick)

(error)

(error)

(error)

(error)

(error)

(error)

(error)

(error)

(error)

(error)

None

     SPACE: The space (" ") character
     N/E: No effect
     NTBS: char* argument pointing to a null-terminated character string
     NTWS: wchar_t* argument pointing to a null-terminated wide character string
     XSI: ISO/IEC 9945-2003 XSI extension

...

Incorrectly specified format strings can result in memory corruption or abnormal program termination.

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

FIO47-C

High

Unlikely

Medium

P6

L2

Automated Detection

Tool

Version

Checker

Description

CodeSonar
Include Page
CodeSonar_V
CodeSonar_V

IO.INJ.FMT
MISC.FMT

Format string injection
Format string

Coverity
Include Page
Coverity_V
Coverity_V
PWReports when the number of arguments differs from the number of required arguments according to the format string
GCC
Include Page
GCC_V
GCC_V

 


Can detect violations of this recommendation when the -Wformat flag is used

Klocwork
Include Page
Klocwork_V
Klocwork_V

SV.FMT_STR.PRINT_FORMAT_MISMATCH.BAD
SV.FMT_STR.PRINT_FORMAT_MISMATCH.UNDESIRED
SV.FMT_STR.PRINT_IMPROP_LENGTH
SV.FMT_STR.PRINT_PARAMS_WRONGNUM.FEW

SV.FMT_STR.PRINT_PARAMS_WRONGNUM.MANY
SV.FMT_STR.SCAN_FORMAT_MISMATCH.BAD
SV.FMT_STR.SCAN_FORMAT_MISMATCH.UNDESIRED
SV.FMT_STR.SCAN_IMPROP_LENGTH
SV.FMT_STR.SCAN_PARAMS_WRONGNUM.FEW
SV.FMT_STR.SCAN_PARAMS_WRONGNUM.MANY
SV.FMT_STR.UNKWN_FORMAT
 


LDRA tool suite
Include Page
LDRA_V
LDRA_V

486 S
589 S

Fully implemented

Parasoft C/C++test
Include Page
c:
Parasoft_V
c:
Parasoft_V
PB-45,PB-46,PB-47,PB-48,PB-49,PB-50Fully implemented
PRQA QA-C
Include Page
PRQA QA-C_v
PRQA QA-C_v

0161, 0162, 0163, 0164, 0165, 0166, 0167, 0168, 0169,

0170, 0171, 0172, 0173, 0174, 0175, 0176, 0177, 0178, 0179 (U),

0180 (C99), 0184 (U), 0185 (U)
0190 (U), 0191 (U), 0192 (U), 0193 (U), 0194 (U)
0195 (U), 0196 (U), 0197 (U), 0198 (U), 0199 (U)
0200 (U), 0201 (U), 0202 (I),
0204, 0206 (U)

Partially implemented
PVS-Studio6.22V510, V576General analysis rule set

Related Vulnerabilities

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

...

Key here (explains table format and definitions)

Taxonomy

Taxonomy item

Relationship

CERT CFIO00-CPP. Take care when creating format stringsPrior to 2018-01-12: CERT: Unspecified Relationship
ISO/IEC TS 17961:2013Using invalid format strings [invfmtstr]Prior to 2018-01-12: CERT: Unspecified Relationship
CWE 2.11CWE-686, Function Call with Incorrect Argument Type2017-06-29: CERT: Partial overlap
CWE 2.11CWE-6852017-06-29: CERT: Partial overlap

CERT-CWE Mapping Notes

Key here for mapping notes

...

  • Using a trusted but invalid format string


Bibliography

[ISO/IEC 9899:2011]Subclause 7.21.6.1, "The fprintf Function"

...


...