From: job Date: Wed, 1 Sep 2021 16:09:54 +0000 (+0000) Subject: Simplify code by replacing strtol() with strtonum() X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=7da26772d21d0d7db47722a3f89a6efe63e4b3fa;p=openbsd Simplify code by replacing strtol() with strtonum() Feedback from deraadt@ --- 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;