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
Don't kill pid -1 on overflow from strtol(3). bdrewery on Mar 4 2017, 9:24 PM. Authored by Tags None Referenced Files
Subscribers None
Details
Store the result in a proper long and then compare to the proper pid_t MFC after: 2 weeks
Diff Detail
Event TimelineComment Actions This 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. |