A format of printf has the %n conversion, which writes to memory
What it finds
printf("%s%n", name, &len): %n stores the number of characters written so far through a pointer argument. It is rarely needed, since the functions return the count, and it is the conversion that turns a format string attack into a write to memory; some libraries refuse it.
From the rule's source, printf_writes_count.rs.
#include <stdio.h> void count(const char *name){ int n; printf("%s%n", name, &n);tx0 reports: the format has %n printf("%d%%n", n);} 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:printf-writes-count" = "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:printf-writes-count] reason="..."tx0 explain tx0/c:printf-writes-count shows the same in the terminal. Found a false positive? Report it.