Author: bdrewery
Date: Sun Mar  5 21:56:04 2017
New Revision: 314714
URL: https://svnweb.freebsd.org/changeset/base/314714

Log:
  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

Modified:
  head/bin/kill/kill.c

Modified: head/bin/kill/kill.c
==============================================================================
--- head/bin/kill/kill.c        Sun Mar  5 21:44:29 2017        (r314713)
+++ head/bin/kill/kill.c        Sun Mar  5 21:56:04 2017        (r314714)
@@ -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);
                }
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to