From 942a2225b3ead6493abb0646fd3dd4f319d3c107 Mon Sep 17 00:00:00 2001 From: gad Date: Tue, 1 Jun 2004 03:01:51 +0000 Subject: Fix so `ps' catches and complains about null-values specified for a process id, instead of using pid==0. Ie, `ps -p 12,' and `ps -p ,12' are now errors (instead of being treated like `ps -p 0 -p 12'). Noticed by: Cyrille Lefevre on freebsd-arch --- bin/ps/ps.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bin/ps/ps.c b/bin/ps/ps.c index df49ab4..90c28af 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -674,9 +674,11 @@ addelem_pid(struct listinfo *inf, const char *elem) char *endp; long tempid; - if (*elem == '\0') - tempid = 0L; - else { + if (*elem == '\0') { + warnx("Invalid (zero-length) process id"); + optfatal = 1; + return (0); /* Do not add this value. */ + } else { errno = 0; tempid = strtol(elem, &endp, 10); if (*endp != '\0' || tempid < 0 || elem == endp) { @@ -787,6 +789,9 @@ add_list(struct listinfo *inf, const char *argp) int toolong; char elemcopy[PATH_MAX]; + if (*argp == 0) + inf->addelem(inf, elemcopy); + while (*argp != '\0') { while (*argp != '\0' && strchr(W_SEP, *argp) != NULL) argp++; -- cgit v1.1