A variable is used as the format of printf without other arguments
What it finds
printf(msg): if the text contains %, printf reads arguments that were never passed, and %n writes to memory; when the text comes from input, that is a way in. printf("%s", msg) or fputs print it as it is.
The format must be a variable, field or element, with no arguments after it; a call such as a translation function is left alone.
From the rule's source, format_from_variable.rs.
#include <stdio.h> struct msg { const char *text; }; void say(const char *msg, struct msg *m, FILE *f){ printf(msg);tx0 reports: msg is used as the format of printf fprintf(f, m->text);tx0 reports: m->text is used as the format of fprintf printf("%s", msg); printf(msg, 1);} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/c:format-from-variable" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/c:format-from-variable] reason="..."tx0 explain tx0/c:format-from-variable shows the same in the terminal. Found a false positive? Report it.