The limit of strncpy is the length of its source

tx0/c:strncpy-source-lengthrecommendedwarningbug, security

What it finds

strncpy(dst, src, strlen(src)): the limit is taken from the source instead of the destination, so it protects nothing, and since it stops just before the terminating zero, dst is left without one. The size of dst was meant, or memcpy if copying the characters alone is the point, which is why the rule is not in the default set.

From the rule's source, strncpy_source_length.rs.

Example from the rule's tests
#include <string.h> void copy(char *dst, const char *src, size_t size){  strncpy(dst, src, strlen(src));tx0 reports: the limit is the length of the source src  strncpy(dst, src, size);  strncpy(dst, src, strlen(dst));  strncpy(dst, src, strlen(src) + 1);}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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/c:strncpy-source-length" = "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:strncpy-source-length] reason="..."

tx0 explain tx0/c:strncpy-source-length shows the same in the terminal. Found a false positive? Report it.