Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 22 Oct 2016 21:41:00 +0000 (UTC)
From:      Martin Matuska <mm@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r307797 - in stable/11/contrib/libarchive: cpio/test libarchive libarchive/test tar/test
Message-ID:  <201610222141.u9MLf0Ih032536@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mm
Date: Sat Oct 22 21:41:00 2016
New Revision: 307797
URL: https://svnweb.freebsd.org/changeset/base/307797

Log:
  MFC r307215:
  Sync libarchive with vendor. Style and tests fixes.
  
  Important vendor bugfixes (relevant to FreeBSD):
  #801: FreeBSD Coverity report: resource leak in libarchive/tar/test/main.c

Modified:
  stable/11/contrib/libarchive/cpio/test/main.c
  stable/11/contrib/libarchive/cpio/test/test.h
  stable/11/contrib/libarchive/libarchive/archive_read_disk_entry_from_file.c
  stable/11/contrib/libarchive/libarchive/archive_read_disk_set_standard_lookup.c
  stable/11/contrib/libarchive/libarchive/test/main.c
  stable/11/contrib/libarchive/libarchive/test/test.h
  stable/11/contrib/libarchive/libarchive/test/test_read_set_format.c
  stable/11/contrib/libarchive/tar/test/main.c
  stable/11/contrib/libarchive/tar/test/test.h
  stable/11/contrib/libarchive/tar/test/test_missing_file.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/contrib/libarchive/cpio/test/main.c
==============================================================================
--- stable/11/contrib/libarchive/cpio/test/main.c	Sat Oct 22 20:57:51 2016	(r307796)
+++ stable/11/contrib/libarchive/cpio/test/main.c	Sat Oct 22 21:41:00 2016	(r307797)
@@ -130,6 +130,13 @@ __FBSDID("$FreeBSD$");
 # 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, in
 	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, 
 	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, in
 	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, in
 			failure_start(file, line,
 			    "Could not write to %s", path);
 			failure_finish(NULL);
+			close(fd);
 			return (0);
 		}
 	}

Modified: stable/11/contrib/libarchive/cpio/test/test.h
==============================================================================
--- stable/11/contrib/libarchive/cpio/test/test.h	Sat Oct 22 20:57:51 2016	(r307796)
+++ stable/11/contrib/libarchive/cpio/test/test.h	Sat Oct 22 21:41:00 2016	(r307797)
@@ -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;
 

Modified: stable/11/contrib/libarchive/libarchive/archive_read_disk_entry_from_file.c
==============================================================================
--- stable/11/contrib/libarchive/libarchive/archive_read_disk_entry_from_file.c	Sat Oct 22 20:57:51 2016	(r307796)
+++ stable/11/contrib/libarchive/libarchive/archive_read_disk_entry_from_file.c	Sat Oct 22 21:41:00 2016	(r307797)
@@ -627,7 +627,6 @@ translate_acl(struct archive_read_disk *
 		archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
 		    "Unknown ACL brand");
 		return (ARCHIVE_WARN);
-		break;
 	}
 #endif
 

Modified: stable/11/contrib/libarchive/libarchive/archive_read_disk_set_standard_lookup.c
==============================================================================
--- stable/11/contrib/libarchive/libarchive/archive_read_disk_set_standard_lookup.c	Sat Oct 22 20:57:51 2016	(r307796)
+++ stable/11/contrib/libarchive/libarchive/archive_read_disk_set_standard_lookup.c	Sat Oct 22 21:41:00 2016	(r307797)
@@ -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);
 

Modified: stable/11/contrib/libarchive/libarchive/test/main.c
==============================================================================
--- stable/11/contrib/libarchive/libarchive/test/main.c	Sat Oct 22 20:57:51 2016	(r307796)
+++ stable/11/contrib/libarchive/libarchive/test/main.c	Sat Oct 22 21:41:00 2016	(r307797)
@@ -128,6 +128,13 @@ __FBSDID("$FreeBSD$");
 # 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 ch
 	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, 
 	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, in
 	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, in
 	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, in
 			failure_start(file, line,
 			    "Could not write to %s", path);
 			failure_finish(NULL);
+			close(fd);
 			return (0);
 		}
 	}

Modified: stable/11/contrib/libarchive/libarchive/test/test.h
==============================================================================
--- stable/11/contrib/libarchive/libarchive/test/test.h	Sat Oct 22 20:57:51 2016	(r307796)
+++ stable/11/contrib/libarchive/libarchive/test/test.h	Sat Oct 22 21:41:00 2016	(r307797)
@@ -243,12 +243,12 @@ int assertion_file_birthtime_recent(cons
 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;
 

Modified: stable/11/contrib/libarchive/libarchive/test/test_read_set_format.c
==============================================================================
--- stable/11/contrib/libarchive/libarchive/test/test_read_set_format.c	Sat Oct 22 20:57:51 2016	(r307796)
+++ stable/11/contrib/libarchive/libarchive/test/test_read_set_format.c	Sat Oct 22 21:41:00 2016	(r307797)
@@ -200,6 +200,8 @@ DEFINE_TEST(test_read_append_filter_wron
 {
   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_wron
     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_wron
   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");
 }

Modified: stable/11/contrib/libarchive/tar/test/main.c
==============================================================================
--- stable/11/contrib/libarchive/tar/test/main.c	Sat Oct 22 20:57:51 2016	(r307796)
+++ stable/11/contrib/libarchive/tar/test/main.c	Sat Oct 22 21:41:00 2016	(r307797)
@@ -1164,6 +1164,35 @@ assertion_file_contains_lines_any_order(
 	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, in
 	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, 
 	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, in
 	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, in
 			failure_start(file, line,
 			    "Could not write to %s", path);
 			failure_finish(NULL);
+			close(fd);
 			return (0);
 		}
 	}

Modified: stable/11/contrib/libarchive/tar/test/test.h
==============================================================================
--- stable/11/contrib/libarchive/tar/test/test.h	Sat Oct 22 20:57:51 2016	(r307796)
+++ stable/11/contrib/libarchive/tar/test/test.h	Sat Oct 22 21:41:00 2016	(r307797)
@@ -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 ch
 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);

Modified: stable/11/contrib/libarchive/tar/test/test_missing_file.c
==============================================================================
--- stable/11/contrib/libarchive/tar/test/test_missing_file.c	Sat Oct 22 20:57:51 2016	(r307796)
+++ stable/11/contrib/libarchive/tar/test/test_missing_file.c	Sat Oct 22 21:41:00 2016	(r307797)
@@ -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);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201610222141.u9MLf0Ih032536>