From nobody Fri Dec 15 16:51:02 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 4SsFbW1Krvz53ngw; Fri, 15 Dec 2023 16:51:03 +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 4SsFbV6Td6z4bQb; Fri, 15 Dec 2023 16:51:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702659062; 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=uM5z6tyATejL+ZIjsR0uxSI5xmB4QrCYuVvN46+0k/U=; b=ffCjp2fSKsoE4jW1rHntxPZY7UvvnlZq56erBtlRM7txxTJ3dlCveSIcRMylYgRXF+2lW8 rPWY3PGe39jukQo5tPR432vBynn1XbgP54F7LMXthdVSAsQ9dmG44Zj7IdYlvQBDdVro4/ LYNEB0MQlM0u2+3gajlEmIYcDgwIAYvMYCMP8tms9kFv4q8VyKCYWTg768u17Hft3vD6Yn aVtEDb0Ow/BWdiO+kby+m9he6FcVvjfR8PI4IU+2doV2BVCqwFJ+GUukQvVo66tEzAGz5r LMWbntWFPhq45fTWHdfUfqXw2rYaIykByraUkb+y+o35rxsOrj0Ik/HlbyTL9A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1702659062; a=rsa-sha256; cv=none; b=NpL6XDTdS6hwT/1DVtxqpIfEbLC/tY24aXoRAfg8d7rrNxNU7aBcGO/bJGg3R5bBDXrSKW G0pjaRA6PD/v2pUfI0ACtlUnBPNZLwSn7L4Vt5d/SuxKwFo8WkuUtY4mHHws0pTxPOatMX X5MdL2nSpMTQvSgdPKp9rXwyNFAqzzkWcdWyN5bw/8rI50J4AAoHtMjSuN9EjR36u9EWnU z/5xCEDXWx6gtMPmu0vIt2I02OWgDXEjylo9U66aIkGqal+m34T5wRnTf+rhxs6V25WQ1M +JRNS1RIYDDFK7wIug1yRXp+0Wq6iToMDCh5GkNKeYWJNTNyxOyB+4ELUtwVQw== 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=1702659062; 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=uM5z6tyATejL+ZIjsR0uxSI5xmB4QrCYuVvN46+0k/U=; b=e/7pObT6CWm1FAEenGhN0YaPGZ38MGC2zmNo36XI7XkitOzVdVLWeaEYdu6xwx8OyLAUh+ GKxEXsZLWgLvL3AJ4tibFWRVGTlK/tv0/iBpLtynmimFnDHLKXfE3716R1wI9K4II3c3q7 7kdYNaOsNj2pGzbs5GFRsrpSp4sYvtG8NTo4YuN8Vn07g2jSymVNjrfxI7vbaC3zJT8XfR qmDkOjKCqETK3kPDY1zWbVmPrYsllRtUf7t6kJzMtOtLpKfW2ay92Ucp/HDmYBcZndu+ZK 2AIlFElVQxoMdV6d2QIN45FVWck7cWbgzpb7qFyzqvPxJjUfE2IMJohfPQPiig== 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 4SsFbV5RPDz3by; Fri, 15 Dec 2023 16:51:02 +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 3BFGp2u2012016; Fri, 15 Dec 2023 16:51:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BFGp2AU012013; Fri, 15 Dec 2023 16:51:02 GMT (envelope-from git) Date: Fri, 15 Dec 2023 16:51:02 GMT Message-Id: <202312151651.3BFGp2AU012013@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: 78e30818a06c - stable/14 - 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/14 X-Git-Reftype: branch X-Git-Commit: 78e30818a06c0cb934637811c3339ea8da9ed16a Auto-Submitted: auto-generated The branch stable/14 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=78e30818a06c0cb934637811c3339ea8da9ed16a commit 78e30818a06c0cb934637811c3339ea8da9ed16a Author: Kyle Evans AuthorDate: 2023-11-26 04:27:11 +0000 Commit: Kyle Evans CommitDate: 2023-12-15 00:58:33 +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 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