Page MenuHomeFreeBSD

Don't kill pid -1 on overflow from strtol(3).
ClosedPublic

Authored by bdrewery on Mar 4 2017, 9:24 PM.
Tags
None
Referenced Files
F105944453: D9887.diff
Sun, Dec 22, 10:28 PM
F105907378: D9887.id26013.diff
Sun, Dec 22, 10:54 AM
Unknown Object (File)
Mon, Dec 2, 4:37 PM
Unknown Object (File)
Mon, Dec 2, 4:37 PM
Unknown Object (File)
Mon, Dec 2, 4:37 PM
Unknown Object (File)
Mon, Dec 2, 4:37 PM
Unknown Object (File)
Mon, Dec 2, 9:38 AM
Unknown Object (File)
Nov 21 2024, 5:58 PM
Subscribers
None

Details

Summary

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

Diff Detail

Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 7918
Build 8056: arc lint + arc unit

Event Timeline

bdrewery retitled this revision from to Don't kill pid -1 on overflow from strtol(3)..
bdrewery updated this object.
bdrewery edited the test plan for this revision. (Show Details)
bdrewery added a reviewer: jilles.
jilles requested changes to this revision.Mar 4 2017, 9:57 PM
jilles edited edge metadata.

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.

This revision now requires changes to proceed.Mar 4 2017, 9:57 PM
bdrewery edited edge metadata.

Store strtol() result in long and compare to pid_t.

bdrewery edited edge metadata.
jilles edited edge metadata.
This revision is now accepted and ready to land.Mar 5 2017, 9:51 PM
This revision was automatically updated to reflect the committed changes.