fix(fprintf): Too few arguments to formatting function #12810
Closed
+1
−30
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Each call to the
printf
function, or a related function, should include the number of arguments defined by the format. Passing the function more arguments than required is harmless (although it may be indicative of other defects). However, passing the function fewer arguments than are defined by the format can be a security vulnerability since the function will process the next item on the stack as the missing arguments. This might lead to an information leak if a sensitive value from the stack is printed. It might cause a crash if a value on the stack is interpreted as a pointer and leads to accessing unmapped memory. Finally, it may lead to a follow-on vulnerability if an attacker can use this problem to cause the output string to be too long or have unexpected contents.fix the issue, ensure that the
fprintf
call provides the correct number of arguments to match the format string. The format string"%X/%X\n"
expects two arguments, so the macroLSN_FORMAT_ARGS(lsn)
must expand to two values. If the macro already provides two values (e.g., a pair of integers), the issue might be with how it is used. If the macro only provides one value, it needs to be replaced or expanded to provide the required two arguments.The fix involves verifying the definition of
LSN_FORMAT_ARGS
and ensuring it provides two arguments. If it does, thefprintf
call should be updated to correctly unpack and pass those arguments. If it does not, the macro or the code using it must be adjusted to supply the missing argument.References
CERT C Coding Standard: FIO47-C. Use valid format strings
Microsoft C Runtime Library Reference: printf, wprintf