diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2000-06-28 19:41:11 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2000-06-28 19:41:11 +0000 |
commit | 13326687121c1fd762b382e7c7588995823b2bc7 (patch) | |
tree | 923060f2f50ad5297c4adafa5a7802dffcadd598 | |
parent | 3decee551253d158a917c1c3945996883ac7df40 (diff) |
Use strtol(), not atoi() when converting a decimal string to an integer.
That way we can catch typos when people say 'kill -HUP 65Q' and not send
the signal to process 65. Theo and myself.
-rw-r--r-- | bin/csh/proc.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/bin/csh/proc.c b/bin/csh/proc.c index c1de6aa85bd..f2976d70408 100644 --- a/bin/csh/proc.c +++ b/bin/csh/proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.c,v 1.11 1998/12/21 05:53:26 deraadt Exp $ */ +/* $OpenBSD: proc.c,v 1.12 2000/06/28 19:41:10 millert Exp $ */ /* $NetBSD: proc.c,v 1.9 1995/04/29 23:21:33 mycroft Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)proc.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$OpenBSD: proc.c,v 1.11 1998/12/21 05:53:26 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: proc.c,v 1.12 2000/06/28 19:41:10 millert Exp $"; #endif #endif /* not lint */ @@ -1105,7 +1105,15 @@ pkill(v, signum) else if (!(Isdigit(*cp) || *cp == '-')) stderror(ERR_NAME | ERR_JOBARGS); else { - pid = atoi(short2str(cp)); + char *ep; + char *pidnam = short2str(cp); + + pid = strtol(pidnam, &ep, 10); + if (!*pidnam || *ep) { + (void) fprintf(csherr, "%s: illegal process id\n", pidnam); + err1++; + goto cont; + } if (kill((pid_t) pid, signum) < 0) { (void) fprintf(csherr, "%d: %s\n", pid, strerror(errno)); err1++; |