From nobody Fri Dec 15 18:57:33 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4SsJPV0rzmz53wnH; Fri, 15 Dec 2023 18:57:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SsJPV0Nq4z3MJP; Fri, 15 Dec 2023 18:57:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702666654; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zd/hM+fWjTE6/+AXplPIHUQnJ0oVS0fulgI88qWSELo=; b=mTq71kzQHY7YjohqFX8aKyx4B5fHqMVNKM2PMyNHpL2GptrUIERbDdeRRcJlgha7Qt+Dpu TokzUFQPiWg3qnh9vIE73IFs+OjExU+e5lNpiX1FfXxL8Bpyy2UwnYdktNAIwO7jl8kHLf PnL/v6y5KhLdS2afem9JbdmqBft5YTTA8Ig3n7EUXrMk8kw/m8cpiNP7BnEevCe9HWL9hb ljYiVcCrHkApo5kmr2fWHXWTNDcPX3xCEsmXrQ3vGiWjWTXaNZ5fnKtuPziWWXS4GaPxuq Oyn1nwq0m4JBSSXK2at59+dwtl/ACm3t91QRnZg1rQhUOqgZlz1OJt8Faz5QUQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1702666654; a=rsa-sha256; cv=none; b=ZENW8weYnwfUgCafQlqJbLBUuBKPBSG0goI84KcsZsDRlbBZjOi4Sj288UoxOdCUbXmQTL Fwdgu+iRXQ8AJKuyp2SPq3CutgBcHfyGZvroK0r+tbult6cOoJPHiLpEfK/t7Jj4f9jdFL oeTbrScXVduThw8gipLkcEMKK/PPyywWhaJjpVcjP29MU+9ftDeZUgzYOwJi6CZ12+SKqP 5m5TDad2zbLdE8rrt88aZl6FtHJpqFMsWwgxe+vV1tGtjRbkrpS8S6zhIkgJEYKjyxhIXL hqC0u4RNZacwQMLTxw4lHPI7SxyQ7/60qWqTd5z+UMdN+au7fKSwXJfoIBkHBw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702666654; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zd/hM+fWjTE6/+AXplPIHUQnJ0oVS0fulgI88qWSELo=; b=tHnQoohCPwxD60VHbQylZ/ZI0MVS+X+BmKigCkYb+ls9Yi/WRIUFnoYideyaYWcwhnQMW2 sBv/eSAiBLInPceb2rNQwdMyX3wZCgrEYwX3WazMKb1LKlBs7NKfR/0KVe4W6b2yQD6Mlf zj9cPVkC44mO571bZtISu+axxR5vUsdxm4hXv0PL0dteUhsHch24LTad2Xkquyx5WNAQNl aR5sUbn8sfpdEvpgkN/LBleQVoAOcbyEBJ9VcR9BGAfJPkFpjOJJQ0zzZx+VXkyHp3UCso bGz5K5sTvNj+ld1/9d0N2rwg0UK7pfQIC+GbNe9Tf5uIDQWD9MLtJw2Ns+C07A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4SsJPT6JFWz7JD; Fri, 15 Dec 2023 18:57:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3BFIvXrc018449; Fri, 15 Dec 2023 18:57:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BFIvXA0018446; Fri, 15 Dec 2023 18:57:33 GMT (envelope-from git) Date: Fri, 15 Dec 2023 18:57:33 GMT Message-Id: <202312151857.3BFIvXA0018446@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: feafc7d0bc74 - stable/13 - lockf: switch to strtonum() for parsing timeout List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: feafc7d0bc74bdf8506e592590c2e7e48e543a96 Auto-Submitted: auto-generated The branch stable/13 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=feafc7d0bc74bdf8506e592590c2e7e48e543a96 commit feafc7d0bc74bdf8506e592590c2e7e48e543a96 Author: Kyle Evans AuthorDate: 2023-11-26 04:27:11 +0000 Commit: Kyle Evans 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