sprintf writes formatted text into a buffer whose size it does not know

tx0/cpp:unbounded-sprintfstrictwarningreliability/memory-safetydepth fastsecurity, cwe-120

What it finds

sprintf(buf, "%s: %s", user, msg) writes as much as the arguments make, however large buf is. snprintf with the size of the buffer cannot run past it.

A call is left alone when the buffer is an array the file declares with a literal length, the format a string literal, and the longest text the format can make fits: numbers and characters only, whose widths are bounded.

From the rule's source, unbounded_sprintf.rs.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/cpp:unbounded-sprintf" = "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/cpp:unbounded-sprintf] reason="..."

tx0 explain tx0/cpp:unbounded-sprintf shows the same in the terminal. Found a false positive? Report it.