Skip to content

Commit

Permalink
utils: use strlcpy when appropriate
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dangowrt committed Jul 7, 2024
1 parent a8cf548 commit f230c11
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions utils/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit f230c11

Please sign in to comment.