diff options
author | Tim Kientzle <kientzle@acm.org> | 2016-10-16 09:44:48 -0700 |
---|---|---|
committer | Tim Kientzle <kientzle@acm.org> | 2016-10-16 09:44:48 -0700 |
commit | d81324dff1a9a413278f8ef4cf30e977d41a8b9d (patch) | |
tree | bc6ce7d49060f569b26917b4302bb8dcf9e6ed3f /libarchive | |
parent | 14144ae97dfdf65f1e3cfc68dbf6719ee0dc03ab (diff) | |
parent | 618bbab5174eb2faa2dd3b7b095359fa26139a38 (diff) | |
download | libarchive-d81324dff1a9a413278f8ef4cf30e977d41a8b9d.tar.gz |
Merge branch 'master' of github.com:libarchive/libarchive
Diffstat (limited to 'libarchive')
-rw-r--r-- | libarchive/archive_read_disk_entry_from_file.c | 1 | ||||
-rw-r--r-- | libarchive/archive_read_disk_set_standard_lookup.c | 2 | ||||
-rw-r--r-- | libarchive/test/main.c | 75 | ||||
-rw-r--r-- | libarchive/test/test.h | 5 | ||||
-rw-r--r-- | libarchive/test/test_acl_freebsd_nfs4.c | 2 | ||||
-rw-r--r-- | libarchive/test/test_read_set_format.c | 23 |
6 files changed, 76 insertions, 32 deletions
diff --git a/libarchive/archive_read_disk_entry_from_file.c b/libarchive/archive_read_disk_entry_from_file.c index 1d49e2a8..4c7f0487 100644 --- a/libarchive/archive_read_disk_entry_from_file.c +++ b/libarchive/archive_read_disk_entry_from_file.c @@ -628,7 +628,6 @@ translate_acl(struct archive_read_disk *a, archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Unknown ACL brand"); return (ARCHIVE_WARN); - break; } #endif diff --git a/libarchive/archive_read_disk_set_standard_lookup.c b/libarchive/archive_read_disk_set_standard_lookup.c index d6b2d55b..c7fd2471 100644 --- a/libarchive/archive_read_disk_set_standard_lookup.c +++ b/libarchive/archive_read_disk_set_standard_lookup.c @@ -232,6 +232,7 @@ static const char * lookup_uname_helper(struct name_cache *cache, id_t id) { struct passwd *result; + (void)cache; /* UNUSED */ result = getpwuid((uid_t)id); @@ -298,6 +299,7 @@ static const char * lookup_gname_helper(struct name_cache *cache, id_t id) { struct group *result; + (void)cache; /* UNUSED */ result = getgrgid((gid_t)id); diff --git a/libarchive/test/main.c b/libarchive/test/main.c index 9fa26fbf..aaa5cfa5 100644 --- a/libarchive/test/main.c +++ b/libarchive/test/main.c @@ -128,6 +128,13 @@ __FBSDID("$FreeBSD: head/lib/libarchive/test/main.c 201247 2009-12-30 05:59:21Z # include <crtdbg.h> #endif +mode_t umasked(mode_t expected_mode) +{ + mode_t mode = umask(0); + umask(mode); + return expected_mode & ~mode; +} + /* Path to working directory for current test */ const char *testworkdir; #ifdef PROGRAM @@ -1364,6 +1371,31 @@ assertion_file_birthtime_recent(const char *file, int line, return assertion_file_time(file, line, pathname, 0, 0, 'b', 1); } +/* Verify mode of 'pathname'. */ +int +assertion_file_mode(const char *file, int line, const char *pathname, int expected_mode) +{ + int mode; + int r; + + assertion_count(file, line); +#if defined(_WIN32) && !defined(__CYGWIN__) + failure_start(file, line, "assertFileMode not yet implemented for Windows"); +#else + { + struct stat st; + r = lstat(pathname, &st); + mode = (int)(st.st_mode & 0777); + } + if (r == 0 && mode == expected_mode) + return (1); + failure_start(file, line, "File %s has mode %o, expected %o", + pathname, mode, expected_mode); +#endif + failure_finish(NULL); + return (0); +} + /* Verify mtime of 'pathname'. */ int assertion_file_mtime(const char *file, int line, @@ -1403,7 +1435,7 @@ assertion_file_nlinks(const char *file, int line, assertion_count(file, line); r = lstat(pathname, &st); if (r == 0 && (int)st.st_nlink == nlinks) - return (1); + return (1); failure_start(file, line, "File %s has %d links, expected %d", pathname, st.st_nlink, nlinks); failure_finish(NULL); @@ -1440,31 +1472,6 @@ assertion_file_size(const char *file, int line, const char *pathname, long size) return (0); } -/* Verify mode of 'pathname'. */ -int -assertion_file_mode(const char *file, int line, const char *pathname, int expected_mode) -{ - int mode; - int r; - - assertion_count(file, line); -#if defined(_WIN32) && !defined(__CYGWIN__) - failure_start(file, line, "assertFileMode not yet implemented for Windows"); -#else - { - struct stat st; - r = lstat(pathname, &st); - mode = (int)(st.st_mode & 0777); - } - if (r == 0 && mode == expected_mode) - return (1); - failure_start(file, line, "File %s has mode %o, expected %o", - pathname, mode, expected_mode); -#endif - failure_finish(NULL); - return (0); -} - /* Assert that 'pathname' is a dir. If mode >= 0, verify that too. */ int assertion_is_dir(const char *file, int line, const char *pathname, int mode) @@ -1607,8 +1614,12 @@ assertion_make_dir(const char *file, int line, const char *dirname, int mode) if (0 == _mkdir(dirname)) return (1); #else - if (0 == mkdir(dirname, mode)) - return (1); + if (0 == mkdir(dirname, mode)) { + if (0 == chmod(dirname, mode)) { + assertion_file_mode(file, line, dirname, mode); + return (1); + } + } #endif failure_start(file, line, "Could not create directory %s", dirname); failure_finish(NULL); @@ -1657,6 +1668,12 @@ assertion_make_file(const char *file, int line, failure_finish(NULL); return (0); } + if (0 != chmod(path, mode)) { + failure_start(file, line, "Could not chmod %s", path); + failure_finish(NULL); + close(fd); + return (0); + } if (contents != NULL) { ssize_t wsize; @@ -1669,10 +1686,12 @@ assertion_make_file(const char *file, int line, failure_start(file, line, "Could not write to %s", path); failure_finish(NULL); + close(fd); return (0); } } close(fd); + assertion_file_mode(file, line, path, mode); return (1); #endif } diff --git a/libarchive/test/test.h b/libarchive/test/test.h index 2fe09ff1..4d503032 100644 --- a/libarchive/test/test.h +++ b/libarchive/test/test.h @@ -243,12 +243,12 @@ int assertion_file_birthtime_recent(const char *, int, const char *); int assertion_file_contains_lines_any_order(const char *, int, const char *, const char **); int assertion_file_contents(const char *, int, const void *, int, const char *); int assertion_file_exists(const char *, int, const char *); +int assertion_file_mode(const char *, int, const char *, int); int assertion_file_mtime(const char *, int, const char *, long, long); int assertion_file_mtime_recent(const char *, int, const char *); int assertion_file_nlinks(const char *, int, const char *, int); int assertion_file_not_exists(const char *, int, const char *); int assertion_file_size(const char *, int, const char *, long); -int assertion_file_mode(const char *, int, const char *, int); int assertion_is_dir(const char *, int, const char *, int); int assertion_is_hardlink(const char *, int, const char *, const char *); int assertion_is_not_hardlink(const char *, int, const char *, const char *); @@ -329,6 +329,9 @@ void copy_reference_file(const char *); */ void extract_reference_files(const char **); +/* Subtract umask from mode */ +mode_t umasked(mode_t expected_mode); + /* Path to working directory for current test */ extern const char *testworkdir; diff --git a/libarchive/test/test_acl_freebsd_nfs4.c b/libarchive/test/test_acl_freebsd_nfs4.c index fd2301d1..89861d6e 100644 --- a/libarchive/test/test_acl_freebsd_nfs4.c +++ b/libarchive/test/test_acl_freebsd_nfs4.c @@ -93,7 +93,7 @@ static struct myacl_t acls_reg[] = { static struct myacl_t acls_dir[] = { /* For this test, we need to be able to read and write the ACL. */ - { ARCHIVE_ENTRY_ACL_TYPE_ALLOW, ARCHIVE_ENTRY_ACL_READ_ACL, + { ARCHIVE_ENTRY_ACL_TYPE_ALLOW, ARCHIVE_ENTRY_ACL_READ_DATA | ARCHIVE_ENTRY_ACL_READ_ACL, ARCHIVE_ENTRY_ACL_USER_OBJ, -1, ""}, /* An entry for each type. */ diff --git a/libarchive/test/test_read_set_format.c b/libarchive/test/test_read_set_format.c index 9208833e..2ebc873d 100644 --- a/libarchive/test/test_read_set_format.c +++ b/libarchive/test/test_read_set_format.c @@ -200,14 +200,24 @@ DEFINE_TEST(test_read_append_filter_wrong_program) { struct archive_entry *ae; struct archive *a; + FILE * fp; + int fd; + fpos_t pos; /* * If we have "bunzip2 -q", try using that. */ - if (!canRunCommand("bunzip2 -V")) { + if (!canRunCommand("bunzip2 -h")) { skipping("Can't run bunzip2 program on this platform"); return; } + + /* bunzip2 will write to stderr, redirect it to a file */ + fflush(stderr); + fgetpos(stderr, &pos); + fd = dup(fileno(stderr)); + fp = freopen("stderr1", "w", stderr); + assert((a = archive_read_new()) != NULL); assertA(0 == archive_read_set_format(a, ARCHIVE_FORMAT_TAR)); assertEqualIntA(a, ARCHIVE_OK, @@ -217,4 +227,15 @@ DEFINE_TEST(test_read_append_filter_wrong_program) assertA(archive_read_next_header(a, &ae) < (ARCHIVE_WARN)); assertEqualIntA(a, ARCHIVE_WARN, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); + + /* restore stderr */ + if (fp != NULL) { + fflush(stderr); + dup2(fd, fileno(stderr)); + close(fd); + clearerr(stderr); + fsetpos(stderr, &pos); + } + + assertTextFileContents("bunzip2: (stdin) is not a bzip2 file.\n", "stderr1"); } |