Skip to content

Commit f9ea674

Browse files
authored
Handle NULL arguments in sigaction (#15114)
Fixes: #15062
1 parent 12b2b67 commit f9ea674

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

system/lib/libc/sigaction.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ int __sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *
2222
*old = __sig_actions[sig];
2323
}
2424

25-
__sig_actions[sig] = *sa;
25+
if (sa) {
26+
__sig_actions[sig] = *sa;
27+
}
28+
2629
return 0;
2730
}
2831

tests/test_signals.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,25 @@ void test_sigwaitinfo() {
127127
assert(!recieved1);
128128
}
129129

130+
void test_sigaction() {
131+
// Use sigaction to find the existing handlers
132+
struct sigaction action;
133+
sigaction(SIGUSR1, NULL, &action);
134+
assert(action.sa_handler == SIG_DFL);
135+
assert((void (*)(int))action.sa_sigaction == SIG_DFL);
136+
137+
// Now install a new handler
138+
action.sa_handler = handler1;
139+
sigaction(SIGUSR1, &action, NULL);
140+
141+
// Verify that the new handler is returned
142+
struct sigaction action2;
143+
sigaction(SIGUSR1, NULL, &action2);
144+
assert(action2.sa_handler == handler1);
145+
}
146+
130147
int main() {
148+
test_sigaction();
131149
test_bad_signal();
132150
test_raise_sigusr1();
133151
test_sigpenging();

0 commit comments

Comments
 (0)