The branch main has been updated by kevans:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=e4967d4d48b0a7d873e4f778c0a6e560e09d4dc3

commit e4967d4d48b0a7d873e4f778c0a6e560e09d4dc3
Author:     Kyle Evans <[email protected]>
AuthorDate: 2023-11-26 04:27:11 +0000
Commit:     Kyle Evans <[email protected]>
CommitDate: 2023-11-26 04:41:05 +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.
---
 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 db45f7a6b2e7..dd02bf2a5417 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

Reply via email to