The result of snprintf is added to an offset or pointer without a check, though it is the length the output would have had
What it finds
len += snprintf(buf + len, size - len, ...): when the output is truncated, snprintf returns the length it would have written, so len passes size, size - len wraps around to a huge value, and the next call writes past the buffer.
From the rule's source, snprintf_result_accumulated.rs.
#include <stdio.h> int list(char *buf, int size, const int *items, int n){ int len = 0; for (int i = 0; i < n; i++) len += snprintf(buf + len, size - len, "%d,", items[i]);tx0 reports: len grows by what snprintf would have written return len;} 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:snprintf-result-accumulated" = "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:snprintf-result-accumulated] reason="..."tx0 explain tx0/c:snprintf-result-accumulated shows the same in the terminal. Found a false positive? Report it.