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 --- main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'main.c') diff --git a/main.c b/main.c index 01ee109f..ff839507 100644 --- a/main.c +++ b/main.c @@ -625,7 +625,8 @@ main(int argc, char *const *argv) goto out; } - const struct sigaction sig_ign = {.sa_handler = SIG_IGN}; + struct sigaction sig_ign = {.sa_handler = SIG_IGN}; + sigemptyset(&sig_ign.sa_mask); if (sigaction(SIGHUP, &sig_ign, NULL) < 0 || sigaction(SIGPIPE, &sig_ign, NULL) < 0) { -- cgit v1.3