From 23cf80667a36aaff1865fc50afab3f98a796cf14 Mon Sep 17 00:00:00 2001 From: Craig Barnes Date: Sat, 12 Feb 2022 12:04:57 +0000 Subject: Explicitly initialize sigaction::sa_mask members with sigemptyset(3) Not doing so before calling sigaction(3) is "undefined" according to POSIX[1]: > Applications shall call either sigemptyset() or sigfillset() at least > once for each object of type sigset_t prior to any other use of that > object. If such an object is not initialized in this way, but is > nonetheless supplied as an argument to any of pthread_sigmask(), > sigaction(), sigaddset(), sigdelset(), sigismember(), sigpending(), > sigprocmask(), sigsuspend(), sigtimedwait(), sigwait(), or > sigwaitinfo(), the results are undefined. The use of designated initializers means that sa_mask members were still being initialized, but sigset_t is an opaque type and implicit initialization doesn't necessarily produce the same results as using sigemptyset(3) (although it typically does on most implementations). [1]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigaddset.html --- fdm.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'fdm.c') diff --git a/fdm.c b/fdm.c index c5eaf6c1..ea30443b 100644 --- a/fdm.c +++ b/fdm.c @@ -352,6 +352,7 @@ fdm_signal_add(struct fdm *fdm, int signo, fdm_signal_handler_t handler, void *d } struct sigaction action = {.sa_handler = &signal_handler}; + sigemptyset(&action.sa_mask); if (sigaction(signo, &action, NULL) < 0) { LOG_ERRNO("failed to set signal handler for signal %d", signo); sigprocmask(SIG_SETMASK, &original, NULL); @@ -371,6 +372,7 @@ fdm_signal_del(struct fdm *fdm, int signo) return false; struct sigaction action = {.sa_handler = SIG_DFL}; + sigemptyset(&action.sa_mask); if (sigaction(signo, &action, NULL) < 0) { LOG_ERRNO("failed to restore signal handler for signal %d", signo); return false; -- cgit v1.3