summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: be12604)
raw | patch | inline | side by side (parent: be12604)
author | Ruben Kerkhof <ruben@rubenkerkhof.com> | |
Sun, 2 Jul 2017 19:48:50 +0000 (21:48 +0200) | ||
committer | Ruben Kerkhof <ruben@rubenkerkhof.com> | |
Sun, 2 Jul 2017 19:48:50 +0000 (21:48 +0200) |
CC src/processes.lo
src/processes.c: In function ‘ps_read’:
src/processes.c:823:58: warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size between 32 and 51 [-Wformat-truncation=]
snprintf(filename, sizeof(filename), "/proc/%li/task/%s/status", ps->id,
^~
src/processes.c:823:5: note: ‘snprintf’ output between 21 and 295 bytes into a destination of size 64
snprintf(filename, sizeof(filename), "/proc/%li/task/%s/status", ps->id,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tpid);
~~~~~
In practice the buffer is more than large enough, since all we substitute are process ids, but gcc can't know that.
src/processes.c: In function ‘ps_read’:
src/processes.c:823:58: warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size between 32 and 51 [-Wformat-truncation=]
snprintf(filename, sizeof(filename), "/proc/%li/task/%s/status", ps->id,
^~
src/processes.c:823:5: note: ‘snprintf’ output between 21 and 295 bytes into a destination of size 64
snprintf(filename, sizeof(filename), "/proc/%li/task/%s/status", ps->id,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tpid);
~~~~~
In practice the buffer is more than large enough, since all we substitute are process ids, but gcc can't know that.
src/processes.c | patch | blob | history |
diff --git a/src/processes.c b/src/processes.c
index 17918c47e7abf1e3fd6eddbed6a14ffdd26795f7..4fec161ed2833e01508d31670ed85f57aba0ea04 100644 (file)
--- a/src/processes.c
+++ b/src/processes.c
tpid = ent->d_name;
- snprintf(filename, sizeof(filename), "/proc/%li/task/%s/status", ps->id,
- tpid);
+ if (snprintf(filename, sizeof(filename), "/proc/%li/task/%s/status", ps->id,
+ tpid) >= sizeof(filename)) {
+ DEBUG("Filename too long: `%s'", filename);
+ continue;
+ }
+
if ((fh = fopen(filename, "r")) == NULL) {
DEBUG("Failed to open file `%s'", filename);
continue;