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
This commit is contained in:
Bryan Drewery 2017-03-05 21:56:04 +00:00
parent 51c6e78d91
commit 27ca6260e0

View File

@ -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);
}