From: Daniel Golle Date: Sun, 7 Jul 2024 16:54:49 +0000 (+0100) Subject: utils: use strlcpy when appropriate X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=f230c11771875adc1f74bef013e8cea1fa1867bc;p=project%2Fprocd.git utils: use strlcpy when appropriate For util functions called with a buffer and length parameter we should use strlcpy() instead of strncpy(), as those functions are called with sizeof(buffer) as parameter. Signed-off-by: Daniel Golle --- diff --git a/utils/utils.c b/utils/utils.c index aa37c86..1939dbd 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -156,7 +156,7 @@ char *get_active_console(char *out, int len) char *newline = strtok(line, "\n"); if (newline != NULL) { - strncpy(out, newline, len); + strlcpy(out, newline, len); return out; } @@ -192,8 +192,7 @@ char *get_cmdline_val_offset(const char *name, char *out, int len, int offset) if (i++ < offset) continue; - strncpy(out, &sep[1], len); - out[len-1] = 0; + strlcpy(out, &sep[1], len); return out; }