Devel prpl
Hi @amin,
I would like to revert your previous commit c0a476de for a couple of reasons.
First one is that it causes compiler errors on glibc strncat implementations, like these:
../dmdiagnostics.c:69:19: error: ‘strncat’ specified bound 7 equals source length [-Werror=stringop-overflow=] 69 | if (tcp->ecn_ns) strncat(tcp_flag, "ECN_NS ", 7); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../dmdiagnostics.c:70:16: error: ‘strncat’ specified bound 4 equals source length [-Werror=stringop-overflow=] 70 | if (tcp->cwr) strncat(tcp_flag, "CWR ", 4); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Second is that strncpy only makes sense when you don't know the length of the source string and want to protect the destination buffer from not being overrun. But in most cases like 'strncat(tcp_flag, "CWR ", 4)', the source string is a constant and strncpy makes no sense.
Another example is from dmoperate.c:
--- a/dmoperate.c +++ b/dmoperate.c @@ -137,7 +137,7 @@ static char *get_param_val_from_op_cmd(char *op_cmd, const char *param) strncpy(node, op_cmd, ret - op_cmd +1);
// Append param name to the trimmed path
-
strcat(node, param);
-
strncat(node, param, strlen(param)); // Get parameter value
strncat will do exactly the same as strcat in this case, when using the length of the source parameter 'param'.
If you want to protect you buffers from overruns by dynamic source strings, you need to pass the destination buffer size to the strn* fuctions.