]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Never follow symlinks when setting file flags on Linux
authorMartin Matuska <martin@matuska.org>
Sun, 22 Aug 2021 01:53:28 +0000 (03:53 +0200)
committerMartin Matuska <martin@matuska.org>
Sun, 22 Aug 2021 01:59:04 +0000 (03:59 +0200)
When opening a file descriptor to set file flags on linux, ensure
no symbolic links are followed. This fixes the case when an archive
contains a directory entry followed by a symlink entry with the same
path. The fixup code would modify file flags of the symlink target.

libarchive/archive_write_disk_posix.c

index ba4e65df7a62cd4368933fc418ecb4d137b6c330..8474617eb5ca98ce12f234990d72e6681ad490a8 100644 (file)
@@ -3927,7 +3927,8 @@ set_fflags_platform(struct archive_write_disk *a, int fd, const char *name,
 
        /* If we weren't given an fd, open it ourselves. */
        if (myfd < 0) {
-               myfd = open(name, O_RDONLY | O_NONBLOCK | O_BINARY | O_CLOEXEC);
+               myfd = open(name, O_RDONLY | O_NONBLOCK | O_BINARY |
+                   O_CLOEXEC | O_NOFOLLOW);
                __archive_ensure_cloexec_flag(myfd);
        }
        if (myfd < 0)