diff options
author | Jean-Francois Brousseau <jfb@cvs.openbsd.org> | 2003-06-17 00:51:30 +0000 |
---|---|---|
committer | Jean-Francois Brousseau <jfb@cvs.openbsd.org> | 2003-06-17 00:51:30 +0000 |
commit | 8c081a572de37430e988e57db5063ee3dad23f7d (patch) | |
tree | d52061ab0765ca95e8fb5326efca15ef61de5d3e | |
parent | dc8d969d73aa0fba53f5753d69c3ecd9fd829d95 (diff) |
properly typecast to uid_t the return value of proc_owner() and report
ESRCH instead of EACCES if it returns -1
ok millert@
-rw-r--r-- | usr.bin/top/commands.c | 9 | ||||
-rw-r--r-- | usr.bin/top/machine.c | 6 |
2 files changed, 9 insertions, 6 deletions
diff --git a/usr.bin/top/commands.c b/usr.bin/top/commands.c index e88892c6359..77d51e8e04d 100644 --- a/usr.bin/top/commands.c +++ b/usr.bin/top/commands.c @@ -1,4 +1,4 @@ -/* $OpenBSD: commands.c,v 1.10 2003/06/15 16:24:44 millert Exp $ */ +/* $OpenBSD: commands.c,v 1.11 2003/06/17 00:51:29 jfb Exp $ */ /* * Top users/processes display for Unix @@ -319,7 +319,7 @@ kill_procs(char *str) { int signum = SIGTERM, procnum; struct sigdesc *sigp; - uid_t uid; + uid_t uid, puid; char *nptr; /* reset error array */ @@ -363,7 +363,10 @@ kill_procs(char *str) ERROR(str, 0); } else { /* check process owner if we're not root */ - if (uid && (uid != proc_owner(procnum))) { + puid = proc_owner(procnum); + if (puid == (uid_t)(-1)) { + ERROR(str, ESRCH); + } else if (uid && (uid != puid)) { ERROR(str, EACCES); } else if (kill(procnum, signum) == -1) { ERROR(str, errno); diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c index 46b4673b049..ad1ceceb849 100644 --- a/usr.bin/top/machine.c +++ b/usr.bin/top/machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machine.c,v 1.33 2003/06/15 16:24:44 millert Exp $ */ +/* $OpenBSD: machine.c,v 1.34 2003/06/17 00:51:29 jfb Exp $ */ /*- * Copyright (c) 1994 Thorsten Lockert <tholo@sigmasoft.com> @@ -621,9 +621,9 @@ proc_owner(pid_t pid) while (--cnt >= 0) { pp = *prefp++; if (PP(pp, p_pid) == pid) - return ((int) EP(pp, e_pcred.p_ruid)); + return ((uid_t) EP(pp, e_pcred.p_ruid)); } - return (-1); + return (uid_t)(-1); } /* |