utils: use strlcpy when appropriate
authorDaniel Golle <daniel@makrotopia.org>
Sun, 7 Jul 2024 16:54:49 +0000 (17:54 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Sun, 7 Jul 2024 17:00:35 +0000 (18:00 +0100)
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 <daniel@makrotopia.org>
utils/utils.c

index aa37c86ef4c127c8bc394b2a14ba602862355aea..1939dbdcab72b02766f6fc04f306c33a64a14a0d 100644 (file)
@@ -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;
        }