From owner-svn-src-head@freebsd.org Tue Oct 4 11:56:49 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D59C2AF5B3B; Tue, 4 Oct 2016 11:56:49 +0000 (UTC) (envelope-from mm@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9C33E812; Tue, 4 Oct 2016 11:56:49 +0000 (UTC) (envelope-from mm@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u94Bum3s043776; Tue, 4 Oct 2016 11:56:48 GMT (envelope-from mm@FreeBSD.org) Received: (from mm@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u94Bukd6043756; Tue, 4 Oct 2016 11:56:46 GMT (envelope-from mm@FreeBSD.org) Message-Id: <201610041156.u94Bukd6043756@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mm set sender to mm@FreeBSD.org using -f From: Martin Matuska Date: Tue, 4 Oct 2016 11:56:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r306670 - in head: contrib/libarchive/cat/test contrib/libarchive/cpio/test contrib/libarchive/libarchive contrib/libarchive/libarchive/test contrib/libarchive/tar contrib/libarchive/ta... X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2016 11:56:49 -0000 Author: mm Date: Tue Oct 4 11:56:46 2016 New Revision: 306670 URL: https://svnweb.freebsd.org/changeset/base/306670 Log: MFV r306669: Sync libarchive with vendor including security fixes. Important vendor bugfixes (relevant to FreeBSD): #747: Out of bounds read in mtree parser #761: heap-based buffer overflow in read_Header (7-zip) #784: Invalid file on bsdtar command line results in internal errors (1) PR: 213092 (1) MFC after: 1 week Added: head/contrib/libarchive/libarchive/test/test_read_format_mtree_crash747.c - copied unchanged from r306669, vendor/libarchive/dist/libarchive/test/test_read_format_mtree_crash747.c head/contrib/libarchive/libarchive/test/test_read_format_mtree_crash747.mtree.bz2.uu - copied unchanged from r306669, vendor/libarchive/dist/libarchive/test/test_read_format_mtree_crash747.mtree.bz2.uu Modified: head/contrib/libarchive/cat/test/main.c head/contrib/libarchive/cat/test/test.h head/contrib/libarchive/cpio/test/main.c head/contrib/libarchive/cpio/test/test.h head/contrib/libarchive/libarchive/archive_read_support_format_7zip.c head/contrib/libarchive/libarchive/archive_read_support_format_mtree.c head/contrib/libarchive/libarchive/test/main.c head/contrib/libarchive/libarchive/test/test_acl_freebsd_nfs4.c head/contrib/libarchive/libarchive/test/test_read_set_format.c head/contrib/libarchive/tar/subst.c head/contrib/libarchive/tar/test/main.c head/contrib/libarchive/tar/test/test.h head/contrib/libarchive/tar/test/test_option_H_upper.c head/contrib/libarchive/tar/test/test_option_L_upper.c head/contrib/libarchive/tar/test/test_option_U_upper.c head/contrib/libarchive/tar/test/test_option_n.c head/contrib/libarchive/tar/write.c head/lib/libarchive/tests/Makefile Directory Properties: head/contrib/libarchive/ (props changed) Modified: head/contrib/libarchive/cat/test/main.c ============================================================================== --- head/contrib/libarchive/cat/test/main.c Tue Oct 4 11:44:21 2016 (r306669) +++ head/contrib/libarchive/cat/test/main.c Tue Oct 4 11:56:46 2016 (r306670) @@ -1360,6 +1360,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, @@ -1578,8 +1603,12 @@ assertion_make_dir(const char *file, int 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); @@ -1628,6 +1657,11 @@ assertion_make_file(const char *file, in failure_finish(NULL); return (0); } + if (0 != chmod(path, mode)) { + failure_start(file, line, "Could not chmod %s", path); + failure_finish(NULL); + return (0); + } if (contents != NULL) { ssize_t wsize; @@ -1644,6 +1678,7 @@ assertion_make_file(const char *file, in } } close(fd); + assertion_file_mode(file, line, path, mode); return (1); #endif } Modified: head/contrib/libarchive/cat/test/test.h ============================================================================== --- head/contrib/libarchive/cat/test/test.h Tue Oct 4 11:44:21 2016 (r306669) +++ head/contrib/libarchive/cat/test/test.h Tue Oct 4 11:56:46 2016 (r306670) @@ -241,6 +241,7 @@ 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); Modified: head/contrib/libarchive/cpio/test/main.c ============================================================================== --- head/contrib/libarchive/cpio/test/main.c Tue Oct 4 11:44:21 2016 (r306669) +++ head/contrib/libarchive/cpio/test/main.c Tue Oct 4 11:56:46 2016 (r306670) @@ -1361,6 +1361,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, @@ -1579,8 +1604,12 @@ assertion_make_dir(const char *file, int 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); @@ -1629,6 +1658,11 @@ assertion_make_file(const char *file, in failure_finish(NULL); return (0); } + if (0 != chmod(path, mode)) { + failure_start(file, line, "Could not chmod %s", path); + failure_finish(NULL); + return (0); + } if (contents != NULL) { ssize_t wsize; @@ -1645,6 +1679,7 @@ assertion_make_file(const char *file, in } } close(fd); + assertion_file_mode(file, line, path, mode); return (1); #endif } Modified: head/contrib/libarchive/cpio/test/test.h ============================================================================== --- head/contrib/libarchive/cpio/test/test.h Tue Oct 4 11:44:21 2016 (r306669) +++ head/contrib/libarchive/cpio/test/test.h Tue Oct 4 11:56:46 2016 (r306670) @@ -241,6 +241,7 @@ 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); Modified: head/contrib/libarchive/libarchive/archive_read_support_format_7zip.c ============================================================================== --- head/contrib/libarchive/libarchive/archive_read_support_format_7zip.c Tue Oct 4 11:44:21 2016 (r306669) +++ head/contrib/libarchive/libarchive/archive_read_support_format_7zip.c Tue Oct 4 11:56:46 2016 (r306670) @@ -2431,6 +2431,8 @@ read_Header(struct archive_read *a, stru switch (type) { case kEmptyStream: + if (h->emptyStreamBools != NULL) + return (-1); h->emptyStreamBools = calloc((size_t)zip->numFiles, sizeof(*h->emptyStreamBools)); if (h->emptyStreamBools == NULL) @@ -2451,6 +2453,8 @@ read_Header(struct archive_read *a, stru return (-1); break; } + if (h->emptyFileBools != NULL) + return (-1); h->emptyFileBools = calloc(empty_streams, sizeof(*h->emptyFileBools)); if (h->emptyFileBools == NULL) @@ -2465,6 +2469,8 @@ read_Header(struct archive_read *a, stru return (-1); break; } + if (h->antiBools != NULL) + return (-1); h->antiBools = calloc(empty_streams, sizeof(*h->antiBools)); if (h->antiBools == NULL) @@ -2491,6 +2497,8 @@ read_Header(struct archive_read *a, stru if ((ll & 1) || ll < zip->numFiles * 4) return (-1); + if (zip->entry_names != NULL) + return (-1); zip->entry_names = malloc(ll); if (zip->entry_names == NULL) return (-1); @@ -2543,6 +2551,8 @@ read_Header(struct archive_read *a, stru if ((p = header_bytes(a, 2)) == NULL) return (-1); allAreDefined = *p; + if (h->attrBools != NULL) + return (-1); h->attrBools = calloc((size_t)zip->numFiles, sizeof(*h->attrBools)); if (h->attrBools == NULL) Modified: head/contrib/libarchive/libarchive/archive_read_support_format_mtree.c ============================================================================== --- head/contrib/libarchive/libarchive/archive_read_support_format_mtree.c Tue Oct 4 11:44:21 2016 (r306669) +++ head/contrib/libarchive/libarchive/archive_read_support_format_mtree.c Tue Oct 4 11:56:46 2016 (r306670) @@ -301,6 +301,15 @@ get_line_size(const char *b, ssize_t ava return (avail); } +/* + * <---------------- ravail ---------------------> + * <-- diff ------> <--- avail -----------------> + * <---- len -----------> + * | Previous lines | line being parsed nl extra | + * ^ + * b + * + */ static ssize_t next_line(struct archive_read *a, const char **b, ssize_t *avail, ssize_t *ravail, ssize_t *nl) @@ -339,7 +348,7 @@ next_line(struct archive_read *a, *b += diff; *avail -= diff; tested = len;/* Skip some bytes we already determinated. */ - len = get_line_size(*b, *avail, nl); + len = get_line_size(*b + len, *avail - len, nl); if (len >= 0) len += tested; } Modified: head/contrib/libarchive/libarchive/test/main.c ============================================================================== --- head/contrib/libarchive/libarchive/test/main.c Tue Oct 4 11:44:21 2016 (r306669) +++ head/contrib/libarchive/libarchive/test/main.c Tue Oct 4 11:56:46 2016 (r306670) @@ -1607,8 +1607,12 @@ assertion_make_dir(const char *file, int 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 +1661,11 @@ assertion_make_file(const char *file, in failure_finish(NULL); return (0); } + if (0 != chmod(path, mode)) { + failure_start(file, line, "Could not chmod %s", path); + failure_finish(NULL); + return (0); + } if (contents != NULL) { ssize_t wsize; @@ -1673,6 +1682,7 @@ assertion_make_file(const char *file, in } } close(fd); + assertion_file_mode(file, line, path, mode); return (1); #endif } Modified: head/contrib/libarchive/libarchive/test/test_acl_freebsd_nfs4.c ============================================================================== --- head/contrib/libarchive/libarchive/test/test_acl_freebsd_nfs4.c Tue Oct 4 11:44:21 2016 (r306669) +++ head/contrib/libarchive/libarchive/test/test_acl_freebsd_nfs4.c Tue Oct 4 11:56:46 2016 (r306670) @@ -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. */ Copied: head/contrib/libarchive/libarchive/test/test_read_format_mtree_crash747.c (from r306669, vendor/libarchive/dist/libarchive/test/test_read_format_mtree_crash747.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/contrib/libarchive/libarchive/test/test_read_format_mtree_crash747.c Tue Oct 4 11:56:46 2016 (r306670, copy of r306669, vendor/libarchive/dist/libarchive/test/test_read_format_mtree_crash747.c) @@ -0,0 +1,44 @@ +/*- + * Copyright (c) 2003-2016 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" + + +/* + * Reproduce the crash reported in Github Issue #747. + */ +DEFINE_TEST(test_read_format_mtree_crash747) +{ + const char *reffile = "test_read_format_mtree_crash747.mtree.bz2"; + struct archive *a; + + extract_reference_file(reffile); + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_bzip2(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_mtree(a)); + assertEqualIntA(a, ARCHIVE_FATAL, archive_read_open_filename(a, reffile, 10240)); + assertEqualInt(ARCHIVE_OK, archive_read_free(a)); +} + Copied: head/contrib/libarchive/libarchive/test/test_read_format_mtree_crash747.mtree.bz2.uu (from r306669, vendor/libarchive/dist/libarchive/test/test_read_format_mtree_crash747.mtree.bz2.uu) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/contrib/libarchive/libarchive/test/test_read_format_mtree_crash747.mtree.bz2.uu Tue Oct 4 11:56:46 2016 (r306670, copy of r306669, vendor/libarchive/dist/libarchive/test/test_read_format_mtree_crash747.mtree.bz2.uu) @@ -0,0 +1,6 @@ +begin 600 test_read_format_mtree_crash747.mtree.bz2 +M0EIH.3%!62936:OH@(@``'/[@,`0`@!``'^```)A@9\`$`@@`'4)049!IIH! +MM021-0,F@&@6````9%>$(K!GIC*XFR0`$```J0+:$XP```!D-F)H[#SE9+2' +4+E"L=ASXUI%R(I"HD'ZA(5?1`Q`` +` +end Modified: head/contrib/libarchive/libarchive/test/test_read_set_format.c ============================================================================== --- head/contrib/libarchive/libarchive/test/test_read_set_format.c Tue Oct 4 11:44:21 2016 (r306669) +++ head/contrib/libarchive/libarchive/test/test_read_set_format.c Tue Oct 4 11:56:46 2016 (r306670) @@ -204,7 +204,7 @@ DEFINE_TEST(test_read_append_filter_wron /* * 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; } Modified: head/contrib/libarchive/tar/subst.c ============================================================================== --- head/contrib/libarchive/tar/subst.c Tue Oct 4 11:44:21 2016 (r306669) +++ head/contrib/libarchive/tar/subst.c Tue Oct 4 11:56:46 2016 (r306670) @@ -84,6 +84,7 @@ add_substitution(struct bsdtar *bsdtar, if (rule == NULL) lafe_errc(1, errno, "Out of memory"); rule->next = NULL; + rule->result = NULL; if (subst->last_rule == NULL) subst->first_rule = rule; Modified: head/contrib/libarchive/tar/test/main.c ============================================================================== --- head/contrib/libarchive/tar/test/main.c Tue Oct 4 11:44:21 2016 (r306669) +++ head/contrib/libarchive/tar/test/main.c Tue Oct 4 11:56:46 2016 (r306670) @@ -130,6 +130,13 @@ __FBSDID("$FreeBSD$"); # include #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 @@ -1361,6 +1368,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, @@ -1579,8 +1611,12 @@ assertion_make_dir(const char *file, int 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); @@ -1629,6 +1665,11 @@ assertion_make_file(const char *file, in failure_finish(NULL); return (0); } + if (0 != chmod(path, mode)) { + failure_start(file, line, "Could not chmod %s", path); + failure_finish(NULL); + return (0); + } if (contents != NULL) { ssize_t wsize; @@ -1645,6 +1686,7 @@ assertion_make_file(const char *file, in } } close(fd); + assertion_file_mode(file, line, path, mode); return (1); #endif } Modified: head/contrib/libarchive/tar/test/test.h ============================================================================== --- head/contrib/libarchive/tar/test/test.h Tue Oct 4 11:44:21 2016 (r306669) +++ head/contrib/libarchive/tar/test/test.h Tue Oct 4 11:56:46 2016 (r306670) @@ -241,6 +241,7 @@ 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); @@ -326,6 +327,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: head/contrib/libarchive/tar/test/test_option_H_upper.c ============================================================================== --- head/contrib/libarchive/tar/test/test_option_H_upper.c Tue Oct 4 11:44:21 2016 (r306669) +++ head/contrib/libarchive/tar/test/test_option_H_upper.c Tue Oct 4 11:56:46 2016 (r306670) @@ -83,10 +83,10 @@ DEFINE_TEST(test_option_H_upper) assertChdir("test3"); assertEqualInt(0, systemf("%s -xf archive.tar >c.out 2>c.err", testprog)); - assertIsDir("ld1", 0755); + assertIsDir("ld1", umasked(0755)); assertIsSymlink("d1/linkX", "fileX"); assertIsSymlink("d1/link1", "file1"); - assertIsReg("link2", 0644); + assertIsReg("link2", umasked(0644)); assertIsSymlink("linkY", "d1/fileY"); assertChdir(".."); } Modified: head/contrib/libarchive/tar/test/test_option_L_upper.c ============================================================================== --- head/contrib/libarchive/tar/test/test_option_L_upper.c Tue Oct 4 11:44:21 2016 (r306669) +++ head/contrib/libarchive/tar/test/test_option_L_upper.c Tue Oct 4 11:56:46 2016 (r306670) @@ -69,10 +69,10 @@ DEFINE_TEST(test_option_L_upper) assertChdir("test2"); assertEqualInt(0, systemf("%s -xf archive.tar >c.out 2>c.err", testprog)); - assertIsDir("ld1", 0755); - assertIsReg("d1/link1", 0644); + assertIsDir("ld1", umasked(0755)); + assertIsReg("d1/link1", umasked(0644)); assertIsSymlink("d1/linkX", "fileX"); - assertIsReg("link2", 0644); + assertIsReg("link2", umasked(0644)); assertIsSymlink("linkY", "d1/fileY"); assertChdir(".."); @@ -83,10 +83,10 @@ DEFINE_TEST(test_option_L_upper) assertChdir("test3"); assertEqualInt(0, systemf("%s -xf archive.tar >c.out 2>c.err", testprog)); - assertIsDir("ld1", 0755); - assertIsReg("d1/link1", 0644); + assertIsDir("ld1", umasked(0755)); + assertIsReg("d1/link1", umasked(0644)); assertIsSymlink("d1/linkX", "fileX"); - assertIsReg("link2", 0644); + assertIsReg("link2", umasked(0644)); assertIsSymlink("linkY", "d1/fileY"); assertChdir(".."); } Modified: head/contrib/libarchive/tar/test/test_option_U_upper.c ============================================================================== --- head/contrib/libarchive/tar/test/test_option_U_upper.c Tue Oct 4 11:44:21 2016 (r306669) +++ head/contrib/libarchive/tar/test/test_option_U_upper.c Tue Oct 4 11:56:46 2016 (r306670) @@ -135,7 +135,7 @@ DEFINE_TEST(test_option_U_upper) assertMakeSymlink("d1/file1", "d1/realfile1"); assertEqualInt(0, systemf("%s -xf ../archive.tar d1/file1 >test.out 2>test.err", testprog)); - assertIsReg("d1/file1", 0644); + assertIsReg("d1/file1", umasked(0644)); assertFileContents("d1/file1", 8, "d1/file1"); assertFileContents("realfile1", 9, "d1/realfile1"); assertEmptyFile("test.out"); @@ -150,7 +150,7 @@ DEFINE_TEST(test_option_U_upper) assertMakeSymlink("d1/file1", "d1/realfile1"); assertEqualInt(0, systemf("%s -xPUf ../archive.tar d1/file1 >test.out 2>test.err", testprog)); - assertIsReg("d1/file1", 0644); + assertIsReg("d1/file1", umasked(0644)); assertFileContents("d1/file1", 8, "d1/file1"); assertFileContents("realfile1", 9, "d1/realfile1"); assertEmptyFile("test.out"); Modified: head/contrib/libarchive/tar/test/test_option_n.c ============================================================================== --- head/contrib/libarchive/tar/test/test_option_n.c Tue Oct 4 11:44:21 2016 (r306669) +++ head/contrib/libarchive/tar/test/test_option_n.c Tue Oct 4 11:56:46 2016 (r306670) @@ -55,7 +55,7 @@ DEFINE_TEST(test_option_n) systemf("%s -xf archive.tar >x.out 2>x.err", testprog)); assertEmptyFile("x.out"); assertEmptyFile("x.err"); - assertIsDir("d1", 0755); + assertIsDir("d1", umasked(0755)); assertFileNotExists("d1/file1"); assertChdir(".."); } Modified: head/contrib/libarchive/tar/write.c ============================================================================== --- head/contrib/libarchive/tar/write.c Tue Oct 4 11:44:21 2016 (r306669) +++ head/contrib/libarchive/tar/write.c Tue Oct 4 11:56:46 2016 (r306670) @@ -886,6 +886,8 @@ write_hierarchy(struct bsdtar *bsdtar, s "%s", archive_error_string(disk)); if (r == ARCHIVE_FATAL || r == ARCHIVE_FAILED) { bsdtar->return_value = 1; + archive_entry_free(entry); + archive_read_close(disk); return; } else if (r < ARCHIVE_WARN) continue; Modified: head/lib/libarchive/tests/Makefile ============================================================================== --- head/lib/libarchive/tests/Makefile Tue Oct 4 11:44:21 2016 (r306669) +++ head/lib/libarchive/tests/Makefile Tue Oct 4 11:56:46 2016 (r306670) @@ -151,6 +151,7 @@ TESTS_SRCS= \ test_read_format_lha_bugfix_0.c \ test_read_format_lha_filename.c \ test_read_format_mtree.c \ + test_read_format_mtree_crash747.c \ test_read_format_pax_bz2.c \ test_read_format_rar.c \ test_read_format_rar_encryption_data.c \ @@ -466,6 +467,7 @@ ${PACKAGE}FILES+= test_read_format_lha_l ${PACKAGE}FILES+= test_read_format_lha_lh7.lzh.uu ${PACKAGE}FILES+= test_read_format_lha_withjunk.lzh.uu ${PACKAGE}FILES+= test_read_format_mtree.mtree.uu +${PACKAGE}FILES+= test_read_format_mtree_crash747.mtree.bz2.uu ${PACKAGE}FILES+= test_read_format_mtree_nomagic.mtree.uu ${PACKAGE}FILES+= test_read_format_mtree_nomagic2.mtree.uu ${PACKAGE}FILES+= test_read_format_mtree_nomagic3.mtree.uu