From eef619fc46dd5d837f8635ebe42109167c2c103a Mon Sep 17 00:00:00 2001 From: ligd Date: Mon, 28 Nov 2022 11:32:00 +0800 Subject: [PATCH] signal: correct sigset() return value & errno ref: https://man7.org/linux/man-pages/man3/sigset.3.html The dispositions for SIGKILL and SIGSTOP cannot be changed. Signed-off-by: ligd --- libs/libc/signal/sig_set.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/libs/libc/signal/sig_set.c b/libs/libc/signal/sig_set.c index 722209d90f..24b0fc34ee 100644 --- a/libs/libc/signal/sig_set.c +++ b/libs/libc/signal/sig_set.c @@ -26,6 +26,7 @@ #include #include +#include /**************************************************************************** * Public Functions @@ -98,9 +99,14 @@ _sa_handler_t sigset(int signo, _sa_handler_t func) { _sa_handler_t disposition; sigset_t set; - int ret; + int ret = -EINVAL; - DEBUGASSERT(GOOD_SIGNO(signo) && func != SIG_ERR); + if (signo == SIGKILL || signo == SIGSTOP || !GOOD_SIGNO(signo)) + { + goto err; + } + + DEBUGASSERT(func != SIG_ERR); sigemptyset(&set); sigaddset(&set, signo); @@ -110,7 +116,12 @@ _sa_handler_t sigset(int signo, _sa_handler_t func) if (func == SIG_HOLD) { ret = sigprocmask(SIG_BLOCK, &set, NULL); - disposition = ret < 0 ? SIG_ERR : SIG_HOLD; + if (ret < 0) + { + goto err; + } + + disposition = SIG_HOLD; } /* No.. then signal can handle the other cases */ @@ -132,10 +143,13 @@ _sa_handler_t sigset(int signo, _sa_handler_t func) */ signal(signo, disposition); - disposition = SIG_ERR; + goto err; } } } return disposition; +err: + set_errno(-ret); + return (_sa_handler_t)SIG_ERR; }