Subject: bin/25212: gzip: broken -t handling
To: None <gnats-bugs@gnats.NetBSD.org>
From: Paul Ripke <stix@stix-amd.stix.org.au>
List: netbsd-bugs
Date: 04/17/2004 12:28:17
>Number:         25212
>Category:       bin
>Synopsis:       gzip: broken -t handling
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Apr 17 14:35:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     Paul Ripke
>Release:        NetBSD 2.0_BETA NetBSD-current
>Organization:
>Environment:
	NetBSD: gzip.c,v 1.36 2004/04/12 14:42:14 mrg Exp
System: NetBSD stix-amd.stix.org.au 2.0_BETA NetBSD 2.0_BETA (STIX-AMD) #0: Sat Apr 10 16:13:34 EST 2004 stix@stix-amd.stix.org.au:/export/build/obj.i386/export/build/src/sys/arch/i386/compile/STIX-AMD i386
Architecture: i386
Machine: i386
>Description:

Broken '-t' test handling for multiple files.
Currently fclose(stdout) is run after each file, which
eventually breaks.

>How-To-Repeat:

ksh$ ls -l *.gz
-rw-r--r--  1 stix  wheel  27 Apr 15 20:23 z1.gz
-rw-r--r--  1 stix  wheel  27 Apr 15 20:23 z2.gz
-rw-r--r--  1 stix  wheel  29 Apr 15 20:23 z3.gz
-rw-r--r--  1 stix  wheel  28 Apr 15 20:23 z4.gz
ksh$ gzip -t *.gz
z1.gz:            OK
z2.gz:            OK
gzip: failed fclose: Bad file descriptor
ksh$ 

>Fix:

Something like the following fixes bugs for the gz and bz2 cases.
For compress, more changes are required, since I currently get:
ksh$ ./gzip -t *.Z
gzip: can't read z1.Z: Undefined error: 0
ksh$ 

Index: gzip.c
===================================================================
RCS file: /cvsroot/src/usr.bin/gzip/gzip.c,v
retrieving revision 1.36
diff -u -d -b -w -r1.36 gzip.c
--- gzip.c	12 Apr 2004 14:42:14 -0000	1.36
+++ gzip.c	17 Apr 2004 02:22:34 -0000
@@ -785,7 +785,11 @@
 			maybe_err(1, "open for write: %s", outfile);
 
 		if ((size = unbzip2(in, out)) == 0) {
+#ifdef SMALL
+			if (cflag == 0 && tflag == 0)
+#else
 			if (cflag == 0)
+#endif
 				unlink(outfile);
 			goto lose;
 		}
@@ -860,7 +864,11 @@
 			out = stdout;
 
 		size = gz_uncompress(in, out);
+#ifdef SMALL
+		if (cflag == 0 && tflag == 0) {
+#else
 		if (cflag == 0) {
+#endif
 			if (size == 0) {
 				unlink(outfile);
 				goto lose;
>Release-Note:
>Audit-Trail:
>Unformatted: