Skip to content

Handle NULL arguments in sigaction #15114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion system/lib/libc/sigaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ int __sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *
*old = __sig_actions[sig];
}

__sig_actions[sig] = *sa;
if (sa) {
__sig_actions[sig] = *sa;
}

return 0;
}

Expand Down
18 changes: 18 additions & 0 deletions tests/test_signals.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,25 @@ void test_sigwaitinfo() {
assert(!recieved1);
}

void test_sigaction() {
// Use sigaction to find the existing handlers
struct sigaction action;
sigaction(SIGUSR1, NULL, &action);
assert(action.sa_handler == SIG_DFL);
assert((void (*)(int))action.sa_sigaction == SIG_DFL);

// Now install a new handler
action.sa_handler = handler1;
sigaction(SIGUSR1, &action, NULL);

// Verify that the new handler is returned
struct sigaction action2;
sigaction(SIGUSR1, NULL, &action2);
assert(action2.sa_handler == handler1);
}

int main() {
test_sigaction();
test_bad_signal();
test_raise_sigusr1();
test_sigpenging();
Expand Down