From nobody Sat Feb 25 17:27:09 2023 X-Original-To: dev-commits-src-all@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 4PPDGQ0G61z3tfd0; Sat, 25 Feb 2023 17:27:10 +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 4PPDGP6s8cz3s8t; Sat, 25 Feb 2023 17:27:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677346030; 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=hfh0i25GMQGY6M2vZ6H25xbpROMpZcAlDbdwueXuJz0=; b=MvfVwiIZ3PJWJg6ygZj+07OhM3aul+UUiT6MPsTmvKxWrZwbY8aSKqaI87tnTyqdp7OpEn gTu3cm4zeQObSAu5cPNo6akNLNouaPhASjtdeuZwEJKZkstfTN1jE4beflpBEHBghOyszx Z348xqbMVhedOJHShUtwQ+av/EplDO8JvQetTxIOfebs3JFFNEuJQW8CZHd1eHmXMkEHUP 9yha0GWFAAv+DZjZxOmY5WuwDkibg4upY9woMuR3m41WtiJnZDbPSoCrplvpgFVrNL8du4 +mRPcWWefQjl08nD7btB9CFnY5d45+uDU/ueinJQPoeyTm7B3d1XGKUrl23hTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677346030; 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=hfh0i25GMQGY6M2vZ6H25xbpROMpZcAlDbdwueXuJz0=; b=RuhTcc8HVbwt84kbUb//1DGiw/IY1FBhjgr45s50vKnsDwUXz01UU8W0WwM1DSTJiB24Bo wTo8qlG3YVLDbHM3sZD2ftsGGwziQ7x9Z/WnmFMbBBHv2oIzu96J9ameZvMG7/39c/eSUL APLok5MselYT1/M34C0naPGuGFZHF4GY12/Atd0t0yaE/Zm8UDEK6+KW+JF4ly4GMj9T8U lDaCy0viERdMtyAfGA/IRoRBjJXO1++54aWyqqf6duxGfgzp0cXjXuAzV4lvG378pN12ft 8E405ZVgATaasF+FBfPZ2NT/Ad3MxHpbAOoJ4/dPk03+HeACm57vGqNFUDTe5g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1677346030; a=rsa-sha256; cv=none; b=VDBvwqmW8V6hvxcGyleaSjFQ+1ARGv50ZNVfR/uE2WFd2WHSgVqJn3mLD9O9YhsEm2awGZ KY6Nb4R7129CmGiNFUrvNH7Pmo2X4TtEeY65qQjZtGaaKqQ2UHY7q6F4uiWjLHtrNKmZsK X8bxfSxOtUienSGwiiKWvBdxlVegg20E1zIS4MQpWLNrihQoueGYZEPTJkNgMLEe5AmLTJ pU5gpiCl1dguh7Jy3MieFGofop0G1e4Cfoi5jN+jopwLw9fkj2MsbGPxVUL1EG0FZxHFOO LzPsltY6xG/18YAkJah6G7uniqdzltX2nBx9lxZqJMuY31DmmMoRywL0jSCb8w== 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 4PPDGP5vZGz1C9v; Sat, 25 Feb 2023 17:27:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 31PHR94w056490; Sat, 25 Feb 2023 17:27:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31PHR9LR056489; Sat, 25 Feb 2023 17:27:09 GMT (envelope-from git) Date: Sat, 25 Feb 2023 17:27:09 GMT Message-Id: <202302251727.31PHR9LR056489@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: e052829e3e16 - main - uniq(1): use strtonum to parse options List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e052829e3e16dfd82d0adcbb69fd0e30f47a3a6c Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=e052829e3e16dfd82d0adcbb69fd0e30f47a3a6c commit e052829e3e16dfd82d0adcbb69fd0e30f47a3a6c Author: Daniel Tameling AuthorDate: 2023-02-25 17:25:51 +0000 Commit: Warner Losh CommitDate: 2023-02-25 17:25:51 +0000 uniq(1): use strtonum to parse options Previously strtol was used and the result was directly cast to an int without checking for an overflow. Use strtonum instead since it is safer and tells us what went wrong. Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/643 --- usr.bin/uniq/uniq.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/usr.bin/uniq/uniq.c b/usr.bin/uniq/uniq.c index 5d2a7c1f2245..36fb037df283 100644 --- a/usr.bin/uniq/uniq.c +++ b/usr.bin/uniq/uniq.c @@ -102,7 +102,7 @@ main (int argc, char *argv[]) int ch, comp; size_t prevbuflen, thisbuflen, b1; char *prevline, *thisline, *p; - const char *ifn; + const char *ifn, *errstr;; cap_rights_t rights; (void) setlocale(LC_ALL, ""); @@ -131,14 +131,14 @@ main (int argc, char *argv[]) iflag = 1; break; case 'f': - numfields = strtol(optarg, &p, 10); - if (numfields < 0 || *p) - errx(1, "illegal field skip value: %s", optarg); + numfields = strtonum(optarg, 0, INT_MAX, &errstr); + if (errstr) + errx(1, "field skip value is %s: %s", errstr, optarg); break; case 's': - numchars = strtol(optarg, &p, 10); - if (numchars < 0 || *p) - errx(1, "illegal character skip value: %s", optarg); + numchars = strtonum(optarg, 0, INT_MAX, &errstr); + if (errstr != NULL) + errx(1, "character skip value is %s: %s", errstr, optarg); break; case 'u': uflag = 1;