strncat is given the size of its destination as the number of characters to append

tx0/cpp:strncat-sizedefaultwarningreliability/memory-safetydepth fastbug, security, cwe-805

What it finds

strncat(buf, s, sizeof(buf)): the last argument of strncat is the most it appends, not the size of the buffer. It writes that many characters after those already in the buffer and then a terminating zero, so even into an empty buffer it can write one byte past the end. The room left, sizeof(buf) - strlen(buf) - 1, was meant.

The length must be exactly sizeof of the destination, a variable declared in the file, and the function the C library's.

From the rule's source, strncat_size.rs.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/cpp:strncat-size" = "off"

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:strncat-size] reason="..."

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