ubase

suckless linux base utils
git clone git://git.2f30.org/ubase
Log | Files | Refs | README | LICENSE

commit 2557104494c9592c86b545cdf6de8e40f5702da8
parent 5a06a9f7e1fa161563d285cb7caf0ae8f530ab7c
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sat,  5 Jul 2014 12:51:13 +0000

util/proc: theoretical underflow

Diffstat:
Mutil/proc.c | 7+++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/util/proc.c b/util/proc.c @@ -43,6 +43,7 @@ parsestat(pid_t pid, struct procstat *ps) { char path[PATH_MAX]; FILE *fp; + size_t len; snprintf(path, sizeof(path), "/proc/%d/stat", pid); if (!(fp = fopen(path, "r"))) @@ -58,8 +59,10 @@ parsestat(pid_t pid, struct procstat *ps) &ps->num_threads, &ps->itrealvalue, &ps->starttime, &ps->vsize, &ps->rss, &ps->rsslim); /* Filter out '(' and ')' from comm */ - ps->comm[strlen(ps->comm) - 1] = '\0'; - memmove(ps->comm, ps->comm + 1, strlen(ps->comm)); + if((len = strlen(ps->comm)) > 0) + len--; + ps->comm[len] = '\0'; + memmove(ps->comm, ps->comm + 1, len); fclose(fp); return 0; }