util/proc: theoretical underflow
This commit is contained in:
parent
5a06a9f7e1
commit
2557104494
@ -43,6 +43,7 @@ parsestat(pid_t pid, struct procstat *ps)
|
|||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
snprintf(path, sizeof(path), "/proc/%d/stat", pid);
|
snprintf(path, sizeof(path), "/proc/%d/stat", pid);
|
||||||
if (!(fp = fopen(path, "r")))
|
if (!(fp = fopen(path, "r")))
|
||||||
@ -58,8 +59,10 @@ parsestat(pid_t pid, struct procstat *ps)
|
|||||||
&ps->num_threads, &ps->itrealvalue, &ps->starttime,
|
&ps->num_threads, &ps->itrealvalue, &ps->starttime,
|
||||||
&ps->vsize, &ps->rss, &ps->rsslim);
|
&ps->vsize, &ps->rss, &ps->rsslim);
|
||||||
/* Filter out '(' and ')' from comm */
|
/* Filter out '(' and ')' from comm */
|
||||||
ps->comm[strlen(ps->comm) - 1] = '\0';
|
if((len = strlen(ps->comm)) > 0)
|
||||||
memmove(ps->comm, ps->comm + 1, strlen(ps->comm));
|
len--;
|
||||||
|
ps->comm[len] = '\0';
|
||||||
|
memmove(ps->comm, ps->comm + 1, len);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user