aboutsummaryrefslogtreecommitdiff
path: root/bin/kill
diff options
context:
space:
mode:
authorBryan Drewery <bdrewery@FreeBSD.org>2017-03-05 21:56:04 +0000
committerBryan Drewery <bdrewery@FreeBSD.org>2017-03-05 21:56:04 +0000
commit27ca6260e0f2f83d19d1b37161afec96b6949416 (patch)
tree04af2091b3d5231eb607b8cfcb9f02ad6eb49966 /bin/kill
parent51c6e78d91a72540ae59332710d3505e99da6aef (diff)
downloadsrc-27ca6260e0f2f83d19d1b37161afec96b6949416.tar.gz
src-27ca6260e0f2f83d19d1b37161afec96b6949416.zip
Don't kill pid -1 on overflow from strtol(3).
Store the result in a proper long and then compare to the proper pid_t for overflow, so that no MD assumptions are made. Reviewed by: jilles MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D9887
Notes
Notes: svn path=/head/; revision=314714
Diffstat (limited to 'bin/kill')
-rw-r--r--bin/kill/kill.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/bin/kill/kill.c b/bin/kill/kill.c
index 4e528cca5759..095244638c65 100644
--- a/bin/kill/kill.c
+++ b/bin/kill/kill.c
@@ -66,7 +66,9 @@ static void usage(void);
int
main(int argc, char *argv[])
{
- int errors, numsig, pid, ret;
+ long pidl;
+ pid_t pid;
+ int errors, numsig, ret;
char *ep;
if (argc < 2)
@@ -137,8 +139,10 @@ main(int argc, char *argv[])
else
#endif
{
- pid = strtol(*argv, &ep, 10);
- if (!**argv || *ep)
+ pidl = strtol(*argv, &ep, 10);
+ /* Check for overflow of pid_t. */
+ pid = (pid_t)pidl;
+ if (!**argv || *ep || pid != pidl)
errx(2, "illegal process id: %s", *argv);
ret = kill(pid, numsig);
}