From nobody@FreeBSD.org  Fri Feb  9 20:33:45 2007
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 6CB4916A401
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  9 Feb 2007 20:33:45 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [69.147.83.33])
	by mx1.freebsd.org (Postfix) with ESMTP id 526D813C4C6
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  9 Feb 2007 20:33:45 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id l19KXjQH077020
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 9 Feb 2007 20:33:45 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id l19KXjgr077019;
	Fri, 9 Feb 2007 20:33:45 GMT
	(envelope-from nobody)
Message-Id: <200702092033.l19KXjgr077019@www.freebsd.org>
Date: Fri, 9 Feb 2007 20:33:45 GMT
From: Andrew<andrew+pr2@supernews.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: incorrect error handling in tar(1) for files that change size
X-Send-Pr-Version: www-3.0

>Number:         108990
>Category:       bin
>Synopsis:       incorrect error handling in tar(1) for files that change size
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    kientzle
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Feb 09 20:40:27 GMT 2007
>Closed-Date:    Sun Feb 25 18:55:17 GMT 2007
>Last-Modified:  Sun Feb 25 18:55:17 GMT 2007
>Originator:     Andrew
>Release:        RELENG_6  as of 20070202
>Organization:
Critical Path, Inc
>Environment:
FreeBSD orac.supernews.net 6.2-20070202 FreeBSD 6.2-20070202 #0: Fri Feb  2 16:29:10 UTC 2007     root@supernews.net:/usr/obj/usr/src/sys/SUPERNEWS  i386

>Description:
tar aborts early with a meaningless error message if any file being archived grows in size between the initial stat() call and completing the archive write.

The error message is "tar: (Empty error message)"

The problem is caused by incorrect handling of the return value from archive_write_data called in write_file_data in write.c. This error was not visible until this commit:

http://www.freebsd.org/cgi/cvsweb.cgi/src/usr.bin/tar/write.c.diff?r1=1.47&r2=1.48

which adds an exit(1) call in the event of the incorrectly handled condition.


>How-To-Repeat:
Arrange for a file to grow continuously (assuming the use of an sh-type shell here):

$ (while true; do echo a; done) >>testfile &

Then try and archive it:

$ tar cf test.tar testfile
tar: (Empty error message)


>Fix:
This code in write_file_data (in write.c) appears to be incorrect:

bytes_written = archive_write_data(a, buff, bytes_read);
if (bytes_written <= 0) {
    /* Write failed; this is bad */
    bsdtar_warnc(bsdtar, 0, "%s", archive_error_string(a));
    return (-1);
}

archive_write_data will correctly return 0 if the original size of the file to be archived has already been reached. Unless I'm badly misunderstanding the libarchive code, this call will return < 0, and not == 0, in the event of a real error in writing to the output archive. My suggested fix is therefore simply:

if (bytes_written < 0) {

we are testing this fix locally, and so far it seems to be correct.

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->kientzle 
Responsible-Changed-By: ade 
Responsible-Changed-When: Fri Feb 9 21:04:31 UTC 2007 
Responsible-Changed-Why:  
Hand off to "he who committed the (probable) problem" ;) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=108990 
State-Changed-From-To: open->patched 
State-Changed-By: kientzle 
State-Changed-When: Wed Feb 14 08:17:13 UTC 2007 
State-Changed-Why:  
Fixed in -CURRENT in tar/write.c 1.53. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=108990 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/108990: commit references a PR
Date: Sun, 18 Feb 2007 06:24:04 +0000 (UTC)

 kientzle    2007-02-18 06:23:57 UTC
 
   FreeBSD src repository
 
   Modified files:
     usr.bin/tar          write.c 
   Log:
   Andrew and Colin each pointed out to me that truncating the backup
   of a growing file should not be considered a "bad thing."
   
   PR: bin/108990
   MFC after: 7 days
   Pointy hat: /me
   
   Revision  Changes    Path
   1.54      +0 -2      src/usr.bin/tar/write.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/108990: commit references a PR
Date: Sun, 25 Feb 2007 07:24:52 +0000 (UTC)

 kientzle    2007-02-25 07:24:45 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_6)
     usr.bin/tar          write.c 
   Log:
   MFC write.c 1.54.  This implements -r support for empty or
   nonexistent files and corrects the bad handling of files that
   change size during archiving.
   
   PR: bin/108607
   PR: bin/108990
   
   Revision  Changes    Path
   1.41.2.5  +47 -13    src/usr.bin/tar/write.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: kientzle 
State-Changed-When: Sun Feb 25 18:54:40 UTC 2007 
State-Changed-Why:  
Fixed in -CURRENT and 6-STABLE. 

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