diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-05-03 16:40:02 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-05-03 16:51:41 +0900 |
commit | 08d3fdc37eee9e47084742f837da73878c7aa66f (patch) | |
tree | 88df8a53bfcc9d3d2df85138c1aac596202af348 /src/basic/signal-util.c | |
parent | b296797f1ce68d9ab34e39b6e4383f2a18ed73df (diff) | |
download | systemd-08d3fdc37eee9e47084742f837da73878c7aa66f.tar.gz |
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
Diffstat (limited to 'src/basic/signal-util.c')
-rw-r--r-- | src/basic/signal-util.c | 54 |
1 files changed, 45 insertions, 9 deletions
diff --git a/src/basic/signal-util.c b/src/basic/signal-util.c index bcb4aeb423..30ba8fb111 100644 --- a/src/basic/signal-util.c +++ b/src/basic/signal-util.c @@ -229,23 +229,59 @@ const char *signal_to_string(int signo) { } int signal_from_string(const char *s) { - int signo; - int offset = 0; - unsigned u; + const char *p; + int signo, r; + /* Check that the input is a signal name. */ signo = __signal_from_string(s); if (signo > 0) return signo; - if (startswith(s, "RTMIN+")) { - s += 6; - offset = SIGRTMIN; - } - if (safe_atou(s, &u) >= 0) { - signo = (int) u + offset; + if (safe_atoi(s, &signo) >= 0) { if (SIGNAL_VALID(signo)) return signo; + else + return -ERANGE; + } + + /* Check that the input is RTMIN or + * RTMIN+n (0 <= n <= SIGRTMAX-SIGRTMIN). */ + p = startswith(s, "RTMIN"); + if (p) { + if (*p == '\0') + return SIGRTMIN; + if (*p != '+') + return -EINVAL; + + r = safe_atoi(p, &signo); + if (r < 0) + return r; + + if (signo < 0 || signo > SIGRTMAX - SIGRTMIN) + return -ERANGE; + + return signo + SIGRTMIN; } + + /* Check that the input is RTMAX or + * RTMAX-n (0 <= n <= SIGRTMAX-SIGRTMIN). */ + p = startswith(s, "RTMAX"); + if (p) { + if (*p == '\0') + return SIGRTMAX; + if (*p != '-') + return -EINVAL; + + r = safe_atoi(p, &signo); + if (r < 0) + return r; + + if (signo > 0 || signo < SIGRTMIN - SIGRTMAX) + return -ERANGE; + + return signo + SIGRTMAX; + } + return -EINVAL; } |