sscanf copies a word of its input into a buffer with no limit on its length

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

What it finds

sscanf(line, "%s %d", name, &n): %s and %[ without a width copy a whole word of the input, so a destination smaller than the input string can overflow. Code that sizes the destination after the input is safe, which is why this is apart from scanf-unbounded-string; a width makes the limit visible either way.

From the rule's source, sscanf_unbounded_string.rs.

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:

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

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