summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJob Snijders <job@cvs.openbsd.org>2021-09-01 16:09:55 +0000
committerJob Snijders <job@cvs.openbsd.org>2021-09-01 16:09:55 +0000
commit1006afd4e830c7d004b0f5cdcdca73ad382d8af4 (patch)
tree44ec74a8beda5176aa6c6be6cd83eb80489d94bd
parent265defbeebe192abb73097656541af27a1342b4e (diff)
Simplify code by replacing strtol() with strtonum()
Feedback from deraadt@
-rw-r--r--usr.bin/timeout/timeout.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/usr.bin/timeout/timeout.c b/usr.bin/timeout/timeout.c
index 6ad14e81d1b..b2db5f15cb3 100644
--- a/usr.bin/timeout/timeout.c
+++ b/usr.bin/timeout/timeout.c
@@ -99,9 +99,10 @@ parse_duration(const char *duration)
static int
parse_signal(const char *str)
{
- char *ep;
- int i;
- long sig;
+ char *ep;
+ int i;
+ long sig;
+ const char *errstr;
if (strncasecmp(str, "SIG", 3) == 0) {
str += 3;
@@ -115,11 +116,8 @@ parse_signal(const char *str)
}
errno = 0;
- sig = strtol(str, &ep, 10);
-
- if (str[0] == '\0' || *ep != '\0')
- goto err;
- if (errno == ERANGE && (sig == LONG_MAX || sig == LONG_MIN))
+ sig = strtonum(str, LONG_MIN, LONG_MAX, &errstr);
+ if (errstr != NULL)
goto err;
if (sig >= NSIG || sig < 0)
goto err;