Store the result in a proper long and then compare to the proper pid_t
for overflow, so that no MD assumptions are made.
MFC after: 2 weeks
Differential D9887 Authored by bdrewery on Mar 4 2017, 9:24 PM.
Tags None Referenced Files
Subscribers None
Details
Summary Store the result in a proper long and then compare to the proper pid_t MFC after: 2 weeks
Diff Detail
Event Timelinebdrewery updated this object. jilles edited edge metadata. Comment ActionsThis is correct for architectures where int and long are the same size, but otherwise there may still be surprising behaviour with strings like 4294967295. The return value of strtol() should be stored into a variable of type long (or a type with at least that range). With the current code's use of int for pid, it is easy to check the range. With pid_t, the alternative (in improper style) long parsed = strtol(...); pid_t pid = (pid_t)parsed; if (... || pid != parsed) errx(...); may raise an implementation-defined signal in case of overflow, per C11. GCC and Clang work as expected, though. This revision now requires changes to proceed.Mar 4 2017, 9:57 PM2017-03-04 21:57:22 (UTC+0) bdrewery edited edge metadata. jilles edited edge metadata. This revision is now accepted and ready to land.Mar 5 2017, 9:51 PM2017-03-05 21:51:15 (UTC+0) Closed by commit rS314714: Don't kill pid -1 on overflow from strtol(3). (authored by bdrewery). · Explain WhyMar 5 2017, 9:56 PM2017-03-05 21:56:16 (UTC+0) This revision was automatically updated to reflect the committed changes.
Revision Contents
Diff 25982 bin/kill/kill.c
|
style(9) was recently changed to permit the braces that were here. I personally prefer the braces, especially in cases like this, where the else has braces.