From nobody@FreeBSD.org  Fri Apr  2 23:13:41 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 19BD81065672
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  2 Apr 2010 23:13:40 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id C797E8FC08
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  2 Apr 2010 23:13:40 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o32NDexU067143
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 2 Apr 2010 23:13:40 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o32NDeIs067142;
	Fri, 2 Apr 2010 23:13:40 GMT
	(envelope-from nobody)
Message-Id: <201004022313.o32NDeIs067142@www.freebsd.org>
Date: Fri, 2 Apr 2010 23:13:40 GMT
From: Garrett Cooper <yaneurabeya@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: tar(1) -C functionality unused when -c or -r is specified
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         145308
>Category:       bin
>Synopsis:       tar(1) -C functionality unused when -c or -r is specified
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kientzle
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Apr 02 23:20:06 UTC 2010
>Closed-Date:    Sat Apr 03 20:28:01 UTC 2010
>Last-Modified:  Sun Feb 03 22:28:31 UTC 2013
>Originator:     Garrett Cooper
>Release:        9-CURRENT
>Organization:
Cisco Systems, Inc.
>Environment:
FreeBSD bayonetta.local 9.0-CURRENT FreeBSD 9.0-CURRENT #5 r205310: Sat Mar 20 01:32:51 PDT 2010     gcooper@bayonetta.local:/usr/obj/usr/src/sys/BAYONETTA  amd64
>Description:
$ (cd /var/db/pkg/apr-gdbm-db42-1.3.9.1.3.9_1/ && tar -cvjf /dev/null . -C /tmp) > /dev/null
a .
a ./+CONTENTS
a ./+DESC
a ./+COMMENT
a ./+MTREE_DIRS
a ./+REQUIRED_BY

The following item fails to properly catch chdir fail on r205310's copy of tar(1) // libarchive:

$ (cd /var/db/pkg/apr-gdbm-db42-1.3.9.1.3.9_1/ && tar -cvjf /dev/null . -C /nonexistent/directory)
a .
a ./+CONTENTS
a ./+DESC
a ./+COMMENT
a ./+MTREE_DIRS
a ./+REQUIRED_BY
$

This should have failed immediately instead of continuing on.

-C with -r is also broken in a similar way:

$ (cd /var/db/pkg/apr-gdbm-db42-1.3.9.1.3.9_1/ && tar -rvf /tmp/foo . -C /tmp) > /dev/null
a .
a ./+CONTENTS
a ./+DESC
a ./+COMMENT
a ./+MTREE_DIRS
a ./+REQUIRED_BY

This issue has also been filed upstream in the Google Code project page so that it's visible to folks outside of FreeBSD as well as within FreeBSD:

http://code.google.com/p/libarchive/issues/detail?id=84
>How-To-Repeat:
(cd / && tar -cvf /dev/null . -C /tmp) - should pass and all of the contents of /tmp should be printed if /tmp exists

(cd / && tar -cvf /dev/null . -C /nonexistent/directory) - should flat out fail
tmpdir=$(mktemp -d /tmp.XXXX)

(cd / && tar -rf $tmpdir/foo -C /tmp) - should pass printing out the contents of /tmp again.
>Fix:


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->kientzle 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sat Apr 3 03:11:09 UTC 2010 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=145308 
State-Changed-From-To: open->closed 
State-Changed-By: kientzle 
State-Changed-When: Sat Apr 3 20:25:09 UTC 2010 
State-Changed-Why:  
As documented in tar(1), the -C option only 
affects file arguments that follow it on the 
command line, e.g., 
tar cf output.tar -C /tmp . 
will archive the contents of /tmp. 
The argument ordering here is necessary to support 
multiple -C arguments.  Consider: 
tar cf output.tar . -C /tmp . 

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