aboutsummaryrefslogtreecommitdiff
path: root/core/busybox/patches/install-fix-chown.patch
blob: 31ecd3c85c61b4b5ac83f82e0c36a6f0154b9f11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
chown must precede chmod because on some systems,
chown clears the set[ug]id bits for non-superusers,
resulting in incorrect permissions.
diff --git a/coreutils/install.c b/coreutils/install.c
index 8270490..0256aeb 100644
--- a/coreutils/install.c
+++ b/coreutils/install.c
@@ -244,6 +244,14 @@ int install_main(int argc, char **argv)
 			}
 		}
 
+		/* Set the user and group id */
+		if ((opts & (OPT_OWNER|OPT_GROUP))
+		 && lchown(dest, uid, gid) == -1
+		) {
+			bb_perror_msg("can't change %s of %s", "ownership", dest);
+			ret = EXIT_FAILURE;
+		}
+
 		/* Set the file mode (always, not only with -m).
 		 * GNU coreutils 6.10 is not affected by umask. */
 		if (chmod(dest, mode) == -1) {
@@ -254,13 +262,6 @@ int install_main(int argc, char **argv)
 		if (use_default_selinux_context)
 			setdefaultfilecon(dest);
 #endif
-		/* Set the user and group id */
-		if ((opts & (OPT_OWNER|OPT_GROUP))
-		 && lchown(dest, uid, gid) == -1
-		) {
-			bb_perror_msg("can't change %s of %s", "ownership", dest);
-			ret = EXIT_FAILURE;
-		}
  next:
 		if (ENABLE_FEATURE_CLEAN_UP && isdir)
 			free(dest);