From b32a43b3a825f1e5062e4d8fe78858f7f1d12f5e Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sat, 18 Jan 2025 15:03:18 -0500 Subject: sighook: Fix up siginit() error paths --- src/sighook.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/sighook.c b/src/sighook.c index 820044c..fc0db6d 100644 --- a/src/sighook.c +++ b/src/sighook.c @@ -573,26 +573,32 @@ static int siginit(int sig) { return 0; } - struct sigsave *save = ALLOC(struct sigsave); - if (!save) { + sigset_t updated = signals; + if (sigaddset(&updated, sig) != 0) { return -1; } - save->sig = sig; - if (sigaction(sig, NULL, &save->action) != 0) { - free(save); + struct sigaction original; + if (sigaction(sig, NULL, &original) != 0) { return -1; } - rcu_list_append(&saved, &save->node); - if (sigaction(sig, &action, NULL) != 0) { + struct sigsave *save = ALLOC(struct sigsave); + if (!save) { return -1; } - if (sigaddset(&signals, sig) != 0) { + save->sig = sig; + save->action = original; + rcu_list_append(&saved, &save->node); + + if (sigaction(sig, &action, NULL) != 0) { + rcu_list_remove(&saved, &save->node); + free(save); return -1; } + signals = updated; return 0; } -- cgit v1.2.3