From: Tim Kientzle Date: Sat, 14 Jun 2008 15:11:37 +0000 (-0400) Subject: On some platforms, the GID bit is inherited by subdirectories. X-Git-Tag: v2.6.0~177 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9b0f0b3bc0335170a8af06e650929c5806f330e7;p=thirdparty%2Flibarchive.git On some platforms, the GID bit is inherited by subdirectories. This caused a lot of false failures in the libarchive test harness. Be a little more careful: the GID bit on created directories should only be checked if ARCHIVE_EXTRACT_PERM was used when the dir was created. Submitted by: Carey Evans SVN-Revision: 115 --- diff --git a/libarchive/test/test_read_extract.c b/libarchive/test/test_read_extract.c index bd42fd0c9..36976b0bc 100644 --- a/libarchive/test/test_read_extract.c +++ b/libarchive/test/test_read_extract.c @@ -135,12 +135,18 @@ DEFINE_TEST(test_read_extract) #endif /* Test the entries on disk. */ + /* This first entry was extracted with ARCHIVE_EXTRACT_PERM, + * so the permissions should have been restored exactly, + * including resetting the gid bit on those platforms + * where gid is inherited by subdirs. */ assert(0 == stat("dir_0775", &st)); failure("This was 0775 in archive, and should be 0775 on disk"); - assert(st.st_mode == (S_IFDIR | 0775)); + assertEqualInt(st.st_mode, S_IFDIR | 0775); + /* Everything else was extracted without ARCHIVE_EXTRACT_PERM, + * so there may be some sloppiness about gid bits on directories. */ assert(0 == stat("file", &st)); failure("st.st_mode=%o should be %o", st.st_mode, S_IFREG | 0755); - assert(st.st_mode == (S_IFREG | 0755)); + assertEqualInt(st.st_mode, S_IFREG | 0755); failure("The file extracted to disk is the wrong size."); assert(st.st_size == FILE_BUFF_SIZE); fd = open("file", O_RDONLY); @@ -153,23 +159,26 @@ DEFINE_TEST(test_read_extract) assert(memcmp(buff, file_buff, FILE_BUFF_SIZE) == 0); assert(0 == stat("dir", &st)); failure("This was 0777 in archive, but umask should make it 0755"); - assert(st.st_mode == (S_IFDIR | 0755)); + /* If EXTRACT_PERM wasn't used, be careful to ignore sgid bit + * when checking dir modes, as some systems inherit sgid bit + * from the parent dir. */ + assertEqualInt(0755, st.st_mode & 0777); assert(0 == stat("dir/file", &st)); assert(st.st_mode == (S_IFREG | 0700)); assert(0 == stat("dir2", &st)); - assert(st.st_mode == (S_IFDIR | 0755)); + assertEqualInt(0755, st.st_mode & 0777); assert(0 == stat("dir2/file", &st)); assert(st.st_mode == (S_IFREG | 0000)); assert(0 == stat("dir3", &st)); - assert(st.st_mode == (S_IFDIR | 0710)); + assertEqualInt(0710, st.st_mode & 0777); assert(0 == stat("dir4", &st)); - assert(st.st_mode == (S_IFDIR | 0755)); + assertEqualInt(0755, st.st_mode & 0777); assert(0 == stat("dir4/a", &st)); - assert(st.st_mode == (S_IFDIR | 0755)); + assertEqualInt(0755, st.st_mode & 0777); assert(0 == stat("dir4/b", &st)); - assert(st.st_mode == (S_IFDIR | 0755)); + assertEqualInt(0755, st.st_mode & 0777); assert(0 == stat("dir4/c", &st)); - assert(st.st_mode == (S_IFDIR | 0711)); + assertEqualInt(0711, st.st_mode & 0777); assert(0 == lstat("symlink", &st)); assert(S_ISLNK(st.st_mode)); #if HAVE_LCHMOD diff --git a/libarchive/test/test_write_disk.c b/libarchive/test/test_write_disk.c index 480cf29b5..0576c8ca5 100644 --- a/libarchive/test/test_write_disk.c +++ b/libarchive/test/test_write_disk.c @@ -48,7 +48,11 @@ static void create(struct archive_entry *ae, const char *msg) assert(0 == stat(archive_entry_pathname(ae), &st)); failure("st.st_mode=%o archive_entry_mode(ae)=%o", st.st_mode, archive_entry_mode(ae)); - assert(st.st_mode == (archive_entry_mode(ae) & ~UMASK)); + /* When verifying a dir, ignore the S_ISGID bit, as some systems set + * that automatically. */ + if (archive_entry_filetype(ae) == AE_IFDIR) + st.st_mode &= ~S_ISGID; + assertEqualInt(st.st_mode, archive_entry_mode(ae) & ~UMASK); } static void create_reg_file(struct archive_entry *ae, const char *msg) diff --git a/libarchive/test/test_write_disk_perms.c b/libarchive/test/test_write_disk_perms.c index 4c03c75b4..e0ca9f4ba 100644 --- a/libarchive/test/test_write_disk_perms.c +++ b/libarchive/test/test_write_disk_perms.c @@ -186,7 +186,7 @@ DEFINE_TEST(test_write_disk_perms) /* Check original perms. */ assert(0 == stat("dir_overwrite_0744", &st)); failure("dir_overwrite_0744: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == 0744); + assert((st.st_mode & 0777) == 0744); /* Overwrite shouldn't edit perms. */ assert((ae = archive_entry_new()) != NULL); archive_entry_copy_pathname(ae, "dir_overwrite_0744"); @@ -197,7 +197,7 @@ DEFINE_TEST(test_write_disk_perms) /* Make sure they're unchanged. */ assert(0 == stat("dir_overwrite_0744", &st)); failure("dir_overwrite_0744: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == 0744); + assert((st.st_mode & 0777) == 0744); /* Write a regular file with SUID bit, but don't use _EXTRACT_PERM. */ assert((ae = archive_entry_new()) != NULL); @@ -385,7 +385,7 @@ DEFINE_TEST(test_write_disk_perms) assert(0 == stat("dir_overwrite_0744", &st)); failure("dir_overwrite_0744: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == 0744); + assert((st.st_mode & 0777) == 0744); assert(0 == stat("file_no_suid", &st)); failure("file_0755: st.st_mode=%o", st.st_mode); diff --git a/libarchive/test/test_write_disk_secure.c b/libarchive/test/test_write_disk_secure.c index 80876b46c..2de3efbfa 100644 --- a/libarchive/test/test_write_disk_secure.c +++ b/libarchive/test/test_write_disk_secure.c @@ -115,7 +115,7 @@ DEFINE_TEST(test_write_disk_secure) /* Test the entries on disk. */ assert(0 == lstat("dir", &st)); failure("dir: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == 0755); + assert((st.st_mode & 0777) == 0755); assert(0 == lstat("link_to_dir", &st)); failure("link_to_dir: st.st_mode=%o", st.st_mode); @@ -137,7 +137,7 @@ DEFINE_TEST(test_write_disk_secure) failure("link_to_dir2 should have been re-created as a true dir"); assert(S_ISDIR(st.st_mode)); failure("link_to_dir2: Implicit dir creation should obey umask, but st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == 0755); + assert((st.st_mode & 0777) == 0755); assert(0 == lstat("link_to_dir2/filec", &st)); assert(S_ISREG(st.st_mode));