From f230c11771875adc1f74bef013e8cea1fa1867bc Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Sun, 7 Jul 2024 17:54:49 +0100 Subject: [PATCH] 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 --- utils/utils.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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; } -- 2.30.2