From sjg@juniper.net  Thu Sep 27 11:39:33 2001
Return-Path: <sjg@juniper.net>
Received: from merlot.juniper.net (natint.juniper.net [207.17.136.129])
	by hub.freebsd.org (Postfix) with ESMTP id EF5B437B40D
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 27 Sep 2001 11:39:32 -0700 (PDT)
Received: from sjg-bsd.juniper.net (sjg-bsd.juniper.net [172.17.12.120])
	by merlot.juniper.net (8.11.3/8.11.3) with ESMTP id f8RIdQ042045;
	Thu, 27 Sep 2001 11:39:26 -0700 (PDT)
	(envelope-from sjg@juniper.net)
Received: (from sjg@localhost)
	by sjg-bsd.juniper.net (8.11.1/8.9.3) id f8RIdQG18276;
	Thu, 27 Sep 2001 11:39:26 -0700 (PDT)
	(envelope-from sjg)
Message-Id: <200109271839.f8RIdQG18276@sjg-bsd.juniper.net>
Date: Thu, 27 Sep 2001 11:39:26 -0700 (PDT)
From: Simon Gerraty <sjg@juniper.net>
Reply-To: sjg@juniper.net
To: FreeBSD-gnats-submit@freebsd.org
Cc: bug-tar@gnu.org
Subject: tar ignores complaints from gzip
X-Send-Pr-Version: 3.2

>Number:         30876
>Category:       gnu
>Synopsis:       tar ignores complaints from gzip
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    sobomax
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep 27 11:40:04 PDT 2001
>Closed-Date:    Thu May 09 14:40:48 PDT 2002
>Last-Modified:  Thu May 09 14:40:48 PDT 2002
>Originator:     Simon Gerraty
>Release:        FreeBSD 4.2-RELEASE i386
>Organization:
Juniper Networks Inc.
>Environment:

	

>Description:

	
The patch below fixes a couple of issues with how tar interacts with
its child - gzip.

1. When the child (gzip) exists with a bad status, tar reports it but does
   not propagate the failure to its caller.  This has lead to pkg_add
   attempting to install corrupted binaries when a gzip fails CRC checks
   but tar has read the end of archive marker before gzip exits.

   Tar should never ignore a bad exit status from its child.


2. Tar closes the pipe as soon as it reads the end of archive.
   It understands that this might result in its child dying due to SIGPIPE
   and it ignores that condition.
   However, if the child catches SIGPIPE and just exit's 1, the fix above
   will result in an unnecessary failure.

   Tar should read EOF from the child before closing the pipe.

--sjg

>How-To-Repeat:

	

>Fix:

	

I can't get a connection to anoncvs.freebsd.org, but the following patch
applies cleanly to -current.

Index: buffer.c
===================================================================
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 buffer.c
--- buffer.c	1997/02/26 02:34:43	1.1.1.1
+++ buffer.c	2001/09/19 16:17:31
@@ -1254,6 +1254,20 @@ close_archive ()
   if (f_verify)
     verify_volume ();
 
+#ifndef __MSDOS__
+  /*
+   * closing the child's pipe before reading EOF guarantees that it
+   * will be unhappy - SIGPIPE, or exit 1.
+   * Either way it can screw us, so play nice.
+   */
+  if (childpid && ar_reading) {
+      char buf[BUFSIZ];
+      
+      while ((c = read(archive, buf, sizeof(buf))) > 0)
+	  continue;
+  }
+#endif
+      
   if ((c = rmtclose (archive)) < 0)
     msg_perror ("Warning: can't close %s(%d,%d)", ar_files[cur_ar_file], archive, c);
 
@@ -1291,9 +1305,11 @@ close_archive ()
 		   */
 		  /* Do nothing. */
 		}
-	      else if (WEXITSTATUS (status))
+	      else if (WEXITSTATUS (status)) {
 		msg ("child returned status %d",
 		     WEXITSTATUS (status));
+		  exit (EX_BADARCH);
+	      }
 	    }
 	}
     }
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: johan 
State-Changed-When: Thu May 9 14:39:02 PDT 2002 
State-Changed-Why:  
Fixed in rev 1.5 (MFC 1.2.12.1) of src/gnu/usr.bin/tar/buffer.c 



Responsible-Changed-From-To: freebsd-bugs->sobomax 
Responsible-Changed-By: johan 
Responsible-Changed-When: Thu May 9 14:39:02 PDT 2002 
Responsible-Changed-Why:  
Maxim commited this fix. 

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