From nobody Wed Apr 17 02:04:06 2024 X-Original-To: dev-commits-src-main@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 4VK42t5dTCz5HZ7J; Wed, 17 Apr 2024 02:04:06 +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 4VK42t3P24z4Fyl; Wed, 17 Apr 2024 02:04:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713319446; 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=0IG6ujuCm91VmmHfoGH5G/Arnr/zYHWDdBDfDatNPZc=; b=MAGm1L21JxhpLMhCEWme2br6zbnN0dYDHpfV3n5y1kzgRGtIz4wu1O8bphUDzdt62PA2/I RgUq5uPNBuqHmCPobg5cQbT+sH2i6oxM4BOQR1MlM8OoXTV+l7cfm6D9WscZLlvE5U7hm4 qcH0WGTlpIICvtsrL88rGeZvEPDvW7AJZgGbCTDm/0SFoyZIWf1/zE6uoqhHBVo8FrUp2r Oo9XwTQfh8Z8UrKfoRR4AAi9W13x5ZNlL1WInFheOhmlSfuXU2/ppvtLaT3k6qmOxCC+aN CprIw88HkGyY8yWYR4PAwqhTyY1hTXaGYtB3UbeeTWEZ35tc9TkbLFSTB9VOJg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1713319446; a=rsa-sha256; cv=none; b=T2QNOZrsQ9mTZGbeH5acO8ivDWYJmvlO8fVBLWDhWjwRCwNJGFIXl8pIfaphtRoe64ILrI iHTXF1YHvE/tHCuqhvUFu/PhEiovgAQFIDMy5B2eISn5RI42Inp+1wJw1oNgEkb+ddAVMR 8sMSjxMlUva6qCtns1CFlLMNdrCfca+p44qPFAjuwzvag+05Z9RBtkplDwAbswX/Pjvkgc kmwXNjAte97rFf1owG0NR7iVpclltqW4rBAmlo5WOL+QBjtKFQKP/+OhMeZ3K+labb5XvF eSreIVmmpCKTt5484uWHlrLHq7E0dh9RIzYvhsIOFtDTLF70x/uT716jF3XWfQ== 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=1713319446; 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=0IG6ujuCm91VmmHfoGH5G/Arnr/zYHWDdBDfDatNPZc=; b=YoTvtPkCUY/JXucKrLOkiU31GL0iE4S+DnQeScAbWChpz03wXDqnG714F1CmCSq/5iLCR2 bxojNo1ml4BgQOdIQrLtb3MFVET9aY9zvNE3KCq4nKr+ZRp3jpAr069y5uQtqd/ytnCY4h Nd+lR5p5z0lU0jsd3p/VaNeuVqSzGS6eCFuVwHo/nKufB/u6vmAm5yuACxwBYZ9jVWyyq7 1IdOWBNDL20wPN4A3cK0s/iBQKMi563XI59z/C1ZmoO/ZmQ9MrDypyfGNGSIgnP++T5cXi jldT6W//f4QrVRzA+RcoVwHg1nYS60eWXnW+GLLl9hTu8raQKyrK23c57xWwKQ== 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 4VK42t2ynsz16MM; Wed, 17 Apr 2024 02:04:06 +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 43H246FI034015; Wed, 17 Apr 2024 02:04:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43H246ht034012; Wed, 17 Apr 2024 02:04:06 GMT (envelope-from git) Date: Wed, 17 Apr 2024 02:04:06 GMT Message-Id: <202404170204.43H246ht034012@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 000a533e6d1d - main - install: Assorted nitpickery. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 000a533e6d1db9878296b32d1cc212e11a2cc718 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=000a533e6d1db9878296b32d1cc212e11a2cc718 commit 000a533e6d1db9878296b32d1cc212e11a2cc718 Author: Dag-Erling Smørgrav AuthorDate: 2024-04-17 01:36:42 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-04-17 02:03:31 +0000 install: Assorted nitpickery. * Use `errc()` instead of manually setting `errno` before calling `err()`. * Change one warning into a fatal error. * Drop some unnecessary casts. * `strlcat()` bounds checks were off-by-one. This does not matter in practice because the subsequent code renders an overrun harmless. * We were passing `SSIZE_MAX` to `copy_file_range()` instead of the requested size. This only matters if we're asked to install a file which is still being written to while we are copying it. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D44810 --- usr.bin/xinstall/xinstall.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c index b824c860e9a8..e25ccf5c6eb1 100644 --- a/usr.bin/xinstall/xinstall.c +++ b/usr.bin/xinstall/xinstall.c @@ -371,8 +371,8 @@ main(int argc, char *argv[]) err(EX_OSERR, "%s vanished", to_name); if (S_ISLNK(to_sb.st_mode)) { if (argc != 2) { - errno = ENOTDIR; - err(EX_USAGE, "%s", to_name); + errc(EX_CANTCREAT, ENOTDIR, "%s", + to_name); } install(*argv, to_name, fset, iflags); exit(EX_OK); @@ -398,14 +398,13 @@ main(int argc, char *argv[]) if (!no_target && !dolink) { if (stat(*argv, &from_sb)) err(EX_OSERR, "%s", *argv); - if (!S_ISREG(to_sb.st_mode)) { - errno = EFTYPE; - err(EX_OSERR, "%s", to_name); - } + if (!S_ISREG(to_sb.st_mode)) + errc(EX_CANTCREAT, EFTYPE, "%s", to_name); if (to_sb.st_dev == from_sb.st_dev && - to_sb.st_ino == from_sb.st_ino) - errx(EX_USAGE, - "%s and %s are the same file", *argv, to_name); + to_sb.st_ino == from_sb.st_ino) { + errx(EX_USAGE, "%s and %s are the same file", + *argv, to_name); + } } install(*argv, to_name, fset, iflags); exit(EX_OK); @@ -749,10 +748,10 @@ makelink(const char *from_name, const char *to_name, if (realpath(dir, dst) == NULL) err(EX_OSERR, "%s: realpath", dir); if (strcmp(dst, "/") != 0 && - strlcat(dst, "/", sizeof(dst)) > sizeof(dst)) + strlcat(dst, "/", sizeof(dst)) >= sizeof(dst)) errx(1, "resolved pathname too long"); } - if (strlcat(dst, base, sizeof(dst)) > sizeof(dst)) + if (strlcat(dst, base, sizeof(dst)) >= sizeof(dst)) errx(1, "resolved pathname too long"); free(to_name_copy); @@ -819,10 +818,8 @@ install(const char *from_name, const char *to_name, u_long fset, u_int flags) if (!dolink) { if (stat(from_name, &from_sb)) err(EX_OSERR, "%s", from_name); - if (!S_ISREG(from_sb.st_mode)) { - errno = EFTYPE; - err(EX_OSERR, "%s", from_name); - } + if (!S_ISREG(from_sb.st_mode)) + errc(EX_OSERR, EFTYPE, "%s", from_name); } /* Build the target path. */ if (flags & DIRECTORY) { @@ -846,11 +843,8 @@ install(const char *from_name, const char *to_name, u_long fset, u_int flags) return; } - if (target && !S_ISREG(to_sb.st_mode) && !S_ISLNK(to_sb.st_mode)) { - errno = EFTYPE; - warn("%s", to_name); - return; - } + if (target && !S_ISREG(to_sb.st_mode) && !S_ISLNK(to_sb.st_mode)) + errc(EX_CANTCREAT, EFTYPE, "%s", to_name); if (!devnull && (from_fd = open(from_name, O_RDONLY, 0)) < 0) err(EX_OSERR, "%s", from_name); @@ -1194,9 +1188,9 @@ copy(int from_fd, const char *from_name, int to_fd, const char *to_name, DIGEST_CTX ctx; /* Rewind file descriptors. */ - if (lseek(from_fd, (off_t)0, SEEK_SET) == (off_t)-1) + if (lseek(from_fd, 0, SEEK_SET) < 0) err(EX_OSERR, "lseek: %s", from_name); - if (lseek(to_fd, (off_t)0, SEEK_SET) == (off_t)-1) + if (lseek(to_fd, 0, SEEK_SET) < 0) err(EX_OSERR, "lseek: %s", to_name); #ifndef BOOTSTRAP_XINSTALL @@ -1204,7 +1198,7 @@ copy(int from_fd, const char *from_name, int to_fd, const char *to_name, if (digesttype == DIGEST_NONE) { do { ret = copy_file_range(from_fd, NULL, to_fd, NULL, - SSIZE_MAX, 0); + (size_t)size, 0); } while (ret > 0); if (ret == 0) goto done;