From: Yu Watanabe Date: Thu, 3 May 2018 07:40:02 +0000 (+0900) Subject: util: make signal_from_string() accept RTMIN, RTMAX, and RTMAX-n X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=bfb9b76f0e162a90d3c7f4e508d8be1cab4e1b31;p=elogind.git util: make signal_from_string() accept RTMIN, RTMAX, and RTMAX-n Before this, `signal_from_string()` accepts simple signal name or RTMIN+n. This makes the function also accept RTMIN, RTMAX, and RTMAX-n. Note that RTMIN+0 is equivalent to RTMIN, and RTMAX-0 is to RTMAX. This also fixes the integer overflow reported by oss-fuzz #8064. https://oss-fuzz.com/v2/testcase-detail/5648573352902656 --- diff --git a/src/basic/signal-util.c b/src/basic/signal-util.c index 5bd5c71ce..bf4816fd6 100644 --- a/src/basic/signal-util.c +++ b/src/basic/signal-util.c @@ -234,7 +234,11 @@ int signal_from_string(const char *s) { const char *p; int signo, r; - /* Check that the input is a signal number. */ + /* Check that the input is a signal name. */ + signo = __signal_from_string(s); + if (signo > 0) + return signo; + if (safe_atoi(s, &signo) >= 0) { if (SIGNAL_VALID(signo)) return signo; @@ -242,15 +246,6 @@ int signal_from_string(const char *s) { return -ERANGE; } - /* Drop "SIG" prefix. */ - if (startswith(s, "SIG")) - s += 3; - - /* Check that the input is a signal name. */ - signo = __signal_from_string(s); - if (signo > 0) - return signo; - /* Check that the input is RTMIN or * RTMIN+n (0 <= n <= SIGRTMAX-SIGRTMIN). */ p = startswith(s, "RTMIN"); @@ -292,6 +287,17 @@ int signal_from_string(const char *s) { return -EINVAL; } +int signal_from_string_try_harder(const char *s) { + int signo; + assert(s); + + signo = signal_from_string(s); + if (signo <= 0) + if (startswith(s, "SIG")) + return signal_from_string(s+3); + + return signo; +} #if 0 /// UNNEEDED by elogind void nop_signal_handler(int sig) {