From owner-freebsd-bugs@FreeBSD.ORG Fri Feb 9 20:40:30 2007 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id A27D516A400 for ; Fri, 9 Feb 2007 20:40:30 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [69.147.83.40]) by mx1.freebsd.org (Postfix) with ESMTP id 82D5E13C4A5 for ; Fri, 9 Feb 2007 20:40:30 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id l19KeUcL022637 for ; Fri, 9 Feb 2007 20:40:30 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id l19KeUpj022636; Fri, 9 Feb 2007 20:40:30 GMT (envelope-from gnats) Resent-Date: Fri, 9 Feb 2007 20:40:30 GMT Resent-Message-Id: <200702092040.l19KeUpj022636@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Andrew Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 6CB4916A401 for ; 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 ; 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 ; 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 To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.0 Cc: Subject: bin/108990: incorrect error handling in tar(1) for files that change size X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Feb 2007 20:40:30 -0000 >Number: 108990 >Category: bin >Synopsis: incorrect error handling in tar(1) for files that change size >Confidential: no >Severity: serious >Priority: high >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Feb 09 20:40:27 GMT 2007 >Closed-Date: >Last-Modified: >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: >Unformatted: