NetBSD Problem Report #58577

From www@netbsd.org  Sun Aug 11 05:40:20 2024
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
	 client-signature RSA-PSS (2048 bits) client-digest SHA256)
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id BF2C61A9242
	for <gnats-bugs@gnats.NetBSD.org>; Sun, 11 Aug 2024 05:40:20 +0000 (UTC)
Message-Id: <20240811054019.77BCD1A9243@mollari.NetBSD.org>
Date: Sun, 11 Aug 2024 05:40:19 +0000 (UTC)
From: rvp@SDF.ORG
Reply-To: rvp@SDF.ORG
To: gnats-bugs@NetBSD.org
Subject: install(1) -d issues
X-Send-Pr-Version: www-1.0

>Number:         58577
>Category:       bin
>Synopsis:       install(1) -d issues
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Aug 11 05:45:01 +0000 2024
>Originator:     RVP
>Release:        NetBSD/amd64 10.99.11
>Organization:
>Environment:
NetBSD/amd64 10.99.11
>Description:
install(1) -d has a couple of issues:

1. `install -d' (ie. no dir. given should error out; it doesn't:

```
$ install 2>/dev/null || echo FAIL
FAIL
$ install -d || echo FAIL
$
```

2. After creating a directory, if the chown/chmod fails, install returns
   success and writes the wrong metalog file:

```
$ whoami
rvp
$ install -M /tmp/meta.log -d -m 755 -o root -g wheel /tmp/A
install: /tmp/A: chown/chmod: Operation not permitted
$ echo $?
0
$ cat /tmp/meta.log
./tmp/A type=dir uname=root gname=wheel mode=0755
$
```
>How-To-Repeat:
As above.
>Fix:
---START patch---
diff -urN a/src/usr.bin/xinstall/xinstall.c b/src/usr.bin/xinstall/xinstall.c
--- a/src/usr.bin/xinstall/xinstall.c	2020-10-30 20:05:00.000000000 +0000
+++ b/src/usr.bin/xinstall/xinstall.c	2023-06-30 22:43:06.828747533 +0000
@@ -161,7 +161,7 @@
 static int	do_link(char *, char *);
 static void	do_symlink(char *, char *);
 static void	install(char *, char *, u_int);
-static void	install_dir(char *, u_int);
+static int	install_dir(char *, u_int);
 static void	makelink(char *, char *);
 static void	metadata_log(const char *, const char *, struct timeval *,
 	    const char *, const char *, off_t);
@@ -322,7 +322,7 @@
 		usage();

 	/* must have at least two arguments, except when creating directories */
-	if (argc < 2 && !dodir)
+	if (argc == 0 || (argc < 2 && !dodir))
 		usage();

 	if (digest) {
@@ -384,9 +384,10 @@
 		digesttype = DIGEST_NONE;

 	if (dodir) {
+		int rc = 0;
 		for (; *argv != NULL; ++argv)
-			install_dir(*argv, iflags);
-		exit (0);
+			rc |= install_dir(*argv, iflags);
+		exit (rc);
 	}

 	no_target = stat(to_name = argv[argc - 1], &to_sb);
@@ -1141,12 +1142,13 @@
  * install_dir --
  *	build directory hierarchy
  */
-static void
+static int
 install_dir(char *path, u_int flags)
 {
 	char		*p;
 	struct stat	sb;
 	int		ch;
+	int		rc = EXIT_SUCCESS;

 	for (p = path;; ++p)
 		if (!*p || (p != path && *p  == '/')) {
@@ -1181,8 +1183,11 @@
 	    ((flags & (HASUID | HASGID)) && chown(path, uid, gid) == -1)
 	    || chmod(path, mode) == -1 )) {
 		warn("%s: chown/chmod", path);
+		rc = EXIT_FAILURE;
 	}
-	metadata_log(path, "dir", NULL, NULL, NULL, 0);
+	if (rc == EXIT_SUCCESS)
+		metadata_log(path, "dir", NULL, NULL, NULL, 0);
+	return rc;
 }

 /*
---END patch---

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2024 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.