]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Check if root before operations. 1023/head
authorEric Borisch <eborisch@gmail.com>
Tue, 5 Jun 2018 03:13:43 +0000 (22:13 -0500)
committerEric Borisch <eborisch@gmail.com>
Tue, 5 Jun 2018 03:13:43 +0000 (22:13 -0500)
No overall change to the code path when root; when not root, ensure
created files are initially user writable if we need to do XATTRs or HFS
compression. Mode is fixed later to the desired final mode in this case.

Net of one extra syscall per file to fix the mode at the end only when
all of these are true:
 * Not root
 * Final mode is not owner-writable
 * XATTRs or HFS compression are needed.

These changes make it unexpectedly pass the xattr test on freebsd.

libarchive/archive_write_disk_posix.c

index 101fce9272c4fd0b78914093e4e051689a06a83c..003e17d77367f5f3fb0c2ddcb38c40b579a20d49 100644 (file)
@@ -1712,7 +1712,8 @@ _archive_write_disk_finish_entry(struct archive *_a)
         * which may be the state after set_mode(). Perform
         * set_xattrs() first based on these constraints.
         */
-       if (a->user_uid && (a->todo & TODO_XATTR)) {
+       if (a->user_uid != 0 &&
+           (a->todo & TODO_XATTR)) {
                int r2 = set_xattrs(a);
                if (r2 < ret) ret = r2;
        }
@@ -1732,7 +1733,8 @@ _archive_write_disk_finish_entry(struct archive *_a)
         * since they're implicitly removed by other file changes.
         * We do this last only when root.
         */
-       if (!a->user_uid && (a->todo & TODO_XATTR)) {
+       if (a->user_uid == 0 &&
+           (a->todo & TODO_XATTR)) {
                int r2 = set_xattrs(a);
                if (r2 < ret) ret = r2;
        }
@@ -2237,9 +2239,12 @@ create_filesystem_object(struct archive_write_disk *a)
         */
        mode = final_mode & 0777 & ~a->user_umask;
 
-       if (a->todo & (TODO_HFS_COMPRESSION | 
-                      TODO_XATTR)) {
-               /* Always create writable such that [f]setxattr() works */
+       /* 
+        * Always create writable such that [f]setxattr() works if we're not
+        * root.
+        */
+       if (a->user_uid != 0 &&
+           a->todo & (TODO_HFS_COMPRESSION | TODO_XATTR)) {
                mode |= 0200;
        }