aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Matuska <mm@FreeBSD.org>2016-10-13 11:34:23 +0000
committerMartin Matuska <mm@FreeBSD.org>2016-10-13 11:34:23 +0000
commit62583e4b79b69cebe941750624cd5730c50916fd (patch)
treeb8e200f171b668a724082ca1ac9d296babbf1eee
parentadb01b286db1dc63ea40381f42f6124b9e695253 (diff)
downloadsrc-62583e4b79b69cebe941750624cd5730c50916fd.tar.gz
src-62583e4b79b69cebe941750624cd5730c50916fd.zip
Update vendor/libarchive to git e3bdbbf3475c3abf264e563c753a20972095665e
Important vendor bugfixes (relevant to FreeBSD): #801: FreeBSD Coverity report: resource leak in libarchive/tar/test/main.c
Notes
Notes: svn path=/vendor/libarchive/dist/; revision=307214
-rw-r--r--cpio/test/main.c16
-rw-r--r--cpio/test/test.h5
-rw-r--r--libarchive/archive_read_disk_entry_from_file.c1
-rw-r--r--libarchive/archive_read_disk_set_standard_lookup.c2
-rw-r--r--libarchive/test/main.c61
-rw-r--r--libarchive/test/test.h5
-rw-r--r--libarchive/test/test_read_set_format.c18
-rw-r--r--tar/test/main.c38
-rw-r--r--tar/test/test.h6
-rw-r--r--tar/test/test_missing_file.c6
10 files changed, 127 insertions, 31 deletions
diff --git a/cpio/test/main.c b/cpio/test/main.c
index 29bbc37a46bb..f3b431d0a6df 100644
--- a/cpio/test/main.c
+++ b/cpio/test/main.c
@@ -130,6 +130,13 @@ __FBSDID("$FreeBSD: src/usr.bin/cpio/test/main.c,v 1.3 2008/08/24 04:58:22 kient
# 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
@@ -1294,6 +1301,11 @@ assertion_file_time(const char *file, int line,
switch (type) {
case 'a': filet_nsec = st.st_atimespec.tv_nsec; break;
case 'b': filet = st.st_birthtime;
+ /* FreeBSD filesystems that don't support birthtime
+ * (e.g., UFS1) always return -1 here. */
+ if (filet == -1) {
+ return (1);
+ }
filet_nsec = st.st_birthtimespec.tv_nsec; break;
case 'm': filet_nsec = st.st_mtimespec.tv_nsec; break;
default: fprintf(stderr, "INTERNAL: Bad type %c for file time", type);
@@ -1425,7 +1437,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);
@@ -1661,6 +1673,7 @@ assertion_make_file(const char *file, int line,
if (0 != chmod(path, mode)) {
failure_start(file, line, "Could not chmod %s", path);
failure_finish(NULL);
+ close(fd);
return (0);
}
if (contents != NULL) {
@@ -1675,6 +1688,7 @@ 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);
}
}
diff --git a/cpio/test/test.h b/cpio/test/test.h
index ecc6f27911b2..0a8b31e1c864 100644
--- a/cpio/test/test.h
+++ b/cpio/test/test.h
@@ -182,6 +182,8 @@
assertion_file_nlinks(__FILE__, __LINE__, pathname, nlinks)
#define assertFileSize(pathname, size) \
assertion_file_size(__FILE__, __LINE__, pathname, size)
+#define assertFileMode(pathname, mode) \
+ assertion_file_mode(__FILE__, __LINE__, pathname, mode)
#define assertTextFileContents(text, pathname) \
assertion_text_file_contents(__FILE__, __LINE__, text, pathname)
#define assertFileContainsLinesAnyOrder(pathname, lines) \
@@ -327,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/archive_read_disk_entry_from_file.c b/libarchive/archive_read_disk_entry_from_file.c
index 1d49e2a82424..4c7f04873d06 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 d6b2d55b8d7b..c7fd2471ecbe 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 2fec9396314f..aaa5cfa5d4b6 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)
@@ -1664,6 +1671,7 @@ assertion_make_file(const char *file, int line,
if (0 != chmod(path, mode)) {
failure_start(file, line, "Could not chmod %s", path);
failure_finish(NULL);
+ close(fd);
return (0);
}
if (contents != NULL) {
@@ -1678,6 +1686,7 @@ 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);
}
}
diff --git a/libarchive/test/test.h b/libarchive/test/test.h
index 2fe09ff169b7..4d5030329d53 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_read_set_format.c b/libarchive/test/test_read_set_format.c
index f9be978351c4..d333269c2ee9 100644
--- a/libarchive/test/test_read_set_format.c
+++ b/libarchive/test/test_read_set_format.c
@@ -200,6 +200,8 @@ DEFINE_TEST(test_read_append_filter_wrong_program)
{
struct archive_entry *ae;
struct archive *a;
+ int fd;
+ fpos_t pos;
/*
* If we have "bunzip2 -q", try using that.
@@ -208,6 +210,13 @@ DEFINE_TEST(test_read_append_filter_wrong_program)
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));
+ 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 +226,13 @@ 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 */
+ fflush(stderr);
+ dup2(fd, fileno(stderr));
+ close(fd);
+ clearerr(stderr);
+ fsetpos(stderr, &pos);
+
+ assertTextFileContents("bunzip2: (stdin) is not a bzip2 file.\n", "stderr1");
}
diff --git a/tar/test/main.c b/tar/test/main.c
index a9300d3f2b24..d847964f75e9 100644
--- a/tar/test/main.c
+++ b/tar/test/main.c
@@ -1164,6 +1164,35 @@ assertion_file_contains_lines_any_order(const char *file, int line,
return (0);
}
+/* Verify that a text file does not contains the specified strings */
+int
+assertion_file_contains_no_invalid_strings(const char *file, int line,
+ const char *pathname, const char *strings[])
+{
+ char *buff;
+ int i;
+
+ buff = slurpfile(NULL, "%s", pathname);
+ if (buff == NULL) {
+ failure_start(file, line, "Can't read file: %s", pathname);
+ failure_finish(NULL);
+ return (0);
+ }
+
+ for (i = 0; strings[i] != NULL; ++i) {
+ if (strstr(buff, strings[i]) != NULL) {
+ failure_start(file, line, "Invalid string in %s: %s", pathname,
+ strings[i]);
+ failure_finish(NULL);
+ free(buff);
+ return(0);
+ }
+ }
+
+ free(buff);
+ return (0);
+}
+
/* Test that two paths point to the same file. */
/* As a side-effect, asserts that both files exist. */
static int
@@ -1301,6 +1330,11 @@ assertion_file_time(const char *file, int line,
switch (type) {
case 'a': filet_nsec = st.st_atimespec.tv_nsec; break;
case 'b': filet = st.st_birthtime;
+ /* FreeBSD filesystems that don't support birthtime
+ * (e.g., UFS1) always return -1 here. */
+ if (filet == -1) {
+ return (1);
+ }
filet_nsec = st.st_birthtimespec.tv_nsec; break;
case 'm': filet_nsec = st.st_mtimespec.tv_nsec; break;
default: fprintf(stderr, "INTERNAL: Bad type %c for file time", type);
@@ -1432,7 +1466,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);
@@ -1668,6 +1702,7 @@ assertion_make_file(const char *file, int line,
if (0 != chmod(path, mode)) {
failure_start(file, line, "Could not chmod %s", path);
failure_finish(NULL);
+ close(fd);
return (0);
}
if (contents != NULL) {
@@ -1682,6 +1717,7 @@ 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);
}
}
diff --git a/tar/test/test.h b/tar/test/test.h
index dbf9f2de076e..98415f8538d8 100644
--- a/tar/test/test.h
+++ b/tar/test/test.h
@@ -174,6 +174,9 @@
/* Assert that file contents match a string. */
#define assertFileContents(data, data_size, pathname) \
assertion_file_contents(__FILE__, __LINE__, data, data_size, pathname)
+/* Verify that a file does not contain invalid strings */
+#define assertFileContainsNoInvalidStrings(pathname, strings) \
+ assertion_file_contains_no_invalid_strings(__FILE__, __LINE__, pathname, strings)
#define assertFileMtime(pathname, sec, nsec) \
assertion_file_mtime(__FILE__, __LINE__, pathname, sec, nsec)
#define assertFileMtimeRecent(pathname) \
@@ -182,6 +185,8 @@
assertion_file_nlinks(__FILE__, __LINE__, pathname, nlinks)
#define assertFileSize(pathname, size) \
assertion_file_size(__FILE__, __LINE__, pathname, size)
+#define assertFileMode(pathname, mode) \
+ assertion_file_mode(__FILE__, __LINE__, pathname, mode)
#define assertTextFileContents(text, pathname) \
assertion_text_file_contents(__FILE__, __LINE__, text, pathname)
#define assertFileContainsLinesAnyOrder(pathname, lines) \
@@ -239,6 +244,7 @@ int assertion_file_atime_recent(const char *, int, const char *);
int assertion_file_birthtime(const char *, int, const char *, long, long);
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_contains_no_invalid_strings(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);
diff --git a/tar/test/test_missing_file.c b/tar/test/test_missing_file.c
index e2e5da5bddf7..808e384e10b0 100644
--- a/tar/test/test_missing_file.c
+++ b/tar/test/test_missing_file.c
@@ -27,11 +27,15 @@ __FBSDID("$FreeBSD$");
DEFINE_TEST(test_missing_file)
{
+ const char * invalid_stderr[] = { "INTERNAL ERROR", NULL };
assertMakeFile("file1", 0644, "file1");
assertMakeFile("file2", 0644, "file2");
assert(0 == systemf("%s -cf archive.tar file1 file2 2>stderr1", testprog));
assertEmptyFile("stderr1");
assert(0 != systemf("%s -cf archive.tar file1 file2 file3 2>stderr2", testprog));
+ assertFileContainsNoInvalidStrings("stderr2", invalid_stderr);
assert(0 != systemf("%s -cf archive.tar 2>stderr3", testprog));
- assert(0 != systemf("%s -cf archive.tar file3 2>stderr4", testprog));
+ assertFileContainsNoInvalidStrings("stderr3", invalid_stderr);
+ assert(0 != systemf("%s -cf archive.tar file3 file4 2>stderr4", testprog));
+ assertFileContainsNoInvalidStrings("stderr4", invalid_stderr);
}