strncat is given the size of its destination as the number of characters to append
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.
#include <string.h> void append(char *out, const char *s){ char buf[64]; buf[0] = 0; strncat(buf, s, sizeof(buf));tx0 reports: strncat can append sizeof(buf) characters after those already in buf strncat(buf, s, sizeof buf);tx0 reports: can append sizeof(buf) characters strncat(buf, s, sizeof(buf) - 1); strncat(buf, s, sizeof(buf) - strlen(buf) - 1); strncat(out, s, sizeof(buf));} 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:
[rules]
"tx0/c: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/c:strncat-size] reason="..."tx0 explain tx0/c:strncat-size shows the same in the terminal. Found a false positive? Report it.