From nobody@FreeBSD.org  Tue Dec 14 19:31:10 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 732B3106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 14 Dec 2010 19:31:10 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (unknown [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 46F4E8FC15
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 14 Dec 2010 19:31:10 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id oBEJVAV2034166
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 14 Dec 2010 19:31:10 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id oBEJVAr5034165;
	Tue, 14 Dec 2010 19:31:10 GMT
	(envelope-from nobody)
Message-Id: <201012141931.oBEJVAr5034165@red.freebsd.org>
Date: Tue, 14 Dec 2010 19:31:10 GMT
From: Mark Johnston <markjdb@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch][libarchive] fix error handling in mtree parsing code
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         153154
>Category:       bin
>Synopsis:       [patch][libarchive] fix error handling in mtree parsing code
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kientzle
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Dec 14 19:40:04 UTC 2010
>Closed-Date:    
>Last-Modified:  Mon Oct 10 04:40:15 UTC 2011
>Originator:     Mark Johnston
>Release:        STABLE-8
>Organization:
>Environment:
FreeBSD mark-laptop-bsd.mark-home 8.2-PRERELEASE FreeBSD 8.2-PRERELEASE #7 r+46c51f0-dirty: Tue Dec  7 11:17:13 EST 2010     mark@mark-laptop-bsd.mark-home:/usr/obj/usr/home/mark/src/freebsd_git/src/sys/IPFW_GENERIC  i386
>Description:
When parsing an mtree file, libarchive expects to find a type for each file it encounters. If the type is not set, libarchive complains that the type keyword is missing _and_ that the mtree specification and the actual file type don't match. In the case that the type specification is omitted, I think that libarchive should only report the first error.
>How-To-Repeat:
$ ls
bar.c     foo.c     tar.mtree
$ cat tar.mtree
#mtree
foo.c
bar.c
$ tar -cvf out.tar @tar.mtree
tar: Error reading archive tar.mtree: Missing type keyword in mtree specificationmtree specification has different type for foo.c
tar: Error exit delayed from previous errors.
$ echo $?
1
>Fix:
I attached a patch which has libarchive verify that MTREE_HAS_TYPE is set before potentially reporting that "mtree specification has a different type for ...".

After the patch:

$ tar -cvf out.tar @tar.mtree
tar: Error reading archive tar.mtree: Missing type keyword in mtree specification
tar: Error exit delayed from previous errors.




Patch attached with submission follows:

diff --git a/lib/libarchive/archive_read_support_format_mtree.c b/lib/libarchive/archive_read_support_format_mtree.c
index 8643bb8..c98b04d 100644
--- a/lib/libarchive/archive_read_support_format_mtree.c
+++ b/lib/libarchive/archive_read_support_format_mtree.c
@@ -641,7 +641,7 @@ parse_file(struct archive_read *a, struct archive_entry *entry,
 		    archive_entry_filetype(entry) != AE_IFIFO)
 			mismatched_type = 1;
 
-		if (mismatched_type) {
+		if (mismatched_type && (parsed_kws & MTREE_HAS_TYPE)) {
 			if ((parsed_kws & MTREE_HAS_OPTIONAL) == 0) {
 				archive_set_error(&a->archive,
 				    ARCHIVE_ERRNO_MISC,


>Release-Note:
>Audit-Trail:

From: Mark Johnston <markjdb@gmail.com>
To: bug-followup@FreeBSD.org, markjdb@gmail.com
Cc:  
Subject: Re: bin/153154: [patch][libarchive] fix error handling in mtree
 parsing code
Date: Tue, 14 Dec 2010 15:15:57 -0500

 Actually, I think the patch below is the proper way to handle this.
 Otherwise, things like an invalid type specifier (e.g. type=filee) result
 in the same problem as above.
 
 -Mark
 
 diff --git a/lib/libarchive/archive_read_support_format_mtree.c b/lib/libarchive/archive_read_support_format_mtree.c
 index 8643bb8..9295176 100644
 --- a/lib/libarchive/archive_read_support_format_mtree.c
 +++ b/lib/libarchive/archive_read_support_format_mtree.c
 @@ -641,7 +641,7 @@ parse_file(struct archive_read *a, struct archive_entry *entry,
  		    archive_entry_filetype(entry) != AE_IFIFO)
  			mismatched_type = 1;
  
 -		if (mismatched_type) {
 +		if (mismatched_type && r == ARCHIVE_OK) {
  			if ((parsed_kws & MTREE_HAS_OPTIONAL) == 0) {
  				archive_set_error(&a->archive,
  				    ARCHIVE_ERRNO_MISC,
Responsible-Changed-From-To: freebsd-bugs->kientzle 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Mon Oct 10 04:40:04 UTC 2011 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=153154 
>Unformatted:
