Date: Fri, 15 Dec 2023 18:57:33 GMT From: Kyle Evans <kevans@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: feafc7d0bc74 - stable/13 - lockf: switch to strtonum() for parsing timeout Message-ID: <202312151857.3BFIvXA0018446@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=feafc7d0bc74bdf8506e592590c2e7e48e543a96 commit feafc7d0bc74bdf8506e592590c2e7e48e543a96 Author: Kyle Evans <kevans@FreeBSD.org> AuthorDate: 2023-11-26 04:27:11 +0000 Commit: Kyle Evans <kevans@FreeBSD.org> CommitDate: 2023-12-15 00:59:27 +0000 lockf: switch to strtonum() for parsing timeout Convert waitsec to a long long to be able to hold the full domain of alarm(3) timeout on all platforms, and let strtonum(3) handle the input validation. strtonum(3) also happens to provide a neater interface for error handling, and it already includes our pre-existing empty input check. Sponsored by: Klara, Inc. (cherry picked from commit e4967d4d48b0a7d873e4f778c0a6e560e09d4dc3) --- usr.bin/lockf/lockf.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/usr.bin/lockf/lockf.c b/usr.bin/lockf/lockf.c index 49a4752a967d..f459b54060aa 100644 --- a/usr.bin/lockf/lockf.c +++ b/usr.bin/lockf/lockf.c @@ -92,7 +92,8 @@ fdlock_implied(const char *name, long *ofd) int main(int argc, char **argv) { - int ch, flags, silent, status, waitsec; + int ch, flags, silent, status; + long long waitsec; pid_t child; union lock_subject subj; @@ -112,9 +113,10 @@ main(int argc, char **argv) break; case 't': { - char *endptr; - waitsec = strtol(optarg, &endptr, 0); - if (*optarg == '\0' || *endptr != '\0' || waitsec < 0) + const char *errstr; + + waitsec = strtonum(optarg, 0, UINT_MAX, &errstr); + if (errstr != NULL) errx(EX_USAGE, "invalid timeout \"%s\"", optarg); } @@ -181,7 +183,7 @@ main(int argc, char **argv) sigemptyset(&act.sa_mask); act.sa_flags = 0; /* Note that we do not set SA_RESTART. */ sigaction(SIGALRM, &act, NULL); - alarm(waitsec); + alarm((unsigned int)waitsec); } /* * If the "-k" option is not given, then we must not block when
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202312151857.3BFIvXA0018446>