Skip to content

Commit

Permalink
Kernel: Don't assert on sys$kill() with pid=INT32_MIN
Browse files Browse the repository at this point in the history
On 32-bit platforms, INT32_MIN == -INT32_MIN, so we can't expect this
to always work:

    if (pid < 0)
        positive_pid = -pid; // may still be negative!

This happens because the -INT32_MIN expression becomes a long and is
then truncated back to an int.

Fixes SerenityOS#1312.
  • Loading branch information
awesomekling committed Feb 27, 2020
1 parent 22259bf commit d28fa89
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Kernel/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2213,8 +2213,11 @@ int Process::sys$kill(pid_t pid, int signal)

if (signal < 0 || signal >= 32)
return -EINVAL;
if (pid <= 0)
if (pid <= 0) {
if (pid == INT32_MIN)
return -EINVAL;
return do_killpg(-pid, signal);
}
if (pid == -1) {
// FIXME: Send to all processes.
return -ENOTIMPL;
Expand Down

0 comments on commit d28fa89

Please sign in to comment.