diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-03-28 23:41:07 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-03-28 23:45:52 -0400 |
commit | c309a7137b06516eafc055eaab31df964599a8b3 (patch) | |
tree | 56d7aef3313ca4894418e4ee257f09c44a777206 /src/bootchart | |
parent | 268888765352e4dcf07e40917fef6ab41b7deba1 (diff) | |
download | systemd-c309a7137b06516eafc055eaab31df964599a8b3.tar.gz |
bootchart: properly terminate string
systemd-199/src/bootchart/store.c:289: buffer_size_warning: Calling
strncpy with a maximum size argument of 256 bytes on destination array
"ps->name" of size 256 bytes might leave the destination string
unterminated.
...and indeed, the string was used as NULL-terminated later on.
pid_cmdline_strncpy is renamed to pid_cmdline_strscpy to commemorate
the fact that it *does* properly terminate the string.
Diffstat (limited to 'src/bootchart')
-rw-r--r-- | src/bootchart/store.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/bootchart/store.c b/src/bootchart/store.c index 0253ebb5af..343365e612 100644 --- a/src/bootchart/store.c +++ b/src/bootchart/store.c @@ -34,6 +34,7 @@ #include <time.h> #include "util.h" +#include "strxcpyx.h" #include "store.h" #include "bootchart.h" @@ -89,7 +90,7 @@ static char *bufgetline(char *buf) { return c; } -static int pid_cmdline_strncpy(char *buffer, int pid, size_t buf_len) { +static int pid_cmdline_strscpy(char *buffer, size_t buf_len, int pid) { char filename[PATH_MAX]; int _cleanup_close_ fd=-1; ssize_t n; @@ -286,11 +287,11 @@ schedstat_next: if (!sscanf(buf, "%s %*s %*s", key)) continue; - strncpy(ps->name, key, 256); + strscpy(ps->name, sizeof(ps->name), key); /* cmdline */ if (arg_show_cmdline) - pid_cmdline_strncpy(ps->name, pid, 256); + pid_cmdline_strscpy(ps->name, sizeof(ps->name), pid); /* discard line 2 */ m = bufgetline(buf); @@ -449,11 +450,11 @@ catch_rename: if (!sscanf(buf, "%s %*s %*s", key)) continue; - strncpy(ps->name, key, 256); + strscpy(ps->name, sizeof(ps->name), key); /* cmdline */ if (arg_show_cmdline) - pid_cmdline_strncpy(ps->name, pid, 256); + pid_cmdline_strscpy(ps->name, sizeof(ps->name), pid); } } } |