gzip: don't use an uninitialized file descriptor
authorJim Meyering <meyering@redhat.com>
Sat, 26 Sep 2009 19:22:02 +0000 (21:22 +0200)
committerJim Meyering <meyering@redhat.com>
Sat, 26 Sep 2009 19:22:02 +0000 (21:22 +0200)
gzip interprets an argument of "-" as indicating stdin, but when
"-" is not the first name on the command line, it doesn't work.
* gzip.c (treat_stdin): Initialize "ifd".
Patch and fine description by Lasse Collin in
http://www.mail-archive.com/bug-gzip@gnu.org/msg00213.html
* Makefile.am (check-local): Exercise the fix.  Based on the above.
* NEWS (Bug fixes): Mention this.

Makefile.am
NEWS
gzip.c

index a73becfbfc37b9fa4edd63b19e1eb999026459db..8023f5b946ac786a4d99a9b616869c7b60625820 100644 (file)
@@ -95,6 +95,8 @@ check-local: $(FILES_TO_CHECK) $(bin_PROGRAMS) gzip.doc.gz
        done
        ./gzip -dc $(srcdir)/tests/hufts-segv.gz > /dev/null 2>&1; \
          test $$? = 1
+       k=in-$$$$; printf a | ./gzip > $$k && \
+         test "`cat $$k | ./gzip -dc $$k - $$k`" = aaa && rm $$k
        @echo 'Test succeeded.'
 
 install-exec-hook: remove-installed-links
diff --git a/NEWS b/NEWS
index 947a15373d805850d11d81f12be6ac32d5cba4e8..c9e925448ec6a128607e7d173d9565210c8cab82 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,8 @@ GNU gzip NEWS                                    -*- outline -*-
 
 ** Bug fixes
 
+  gzip -d no longer fails with "-" as 2nd or subsequent argument
+
   gzip no longer ignores a close-induced write failure, e.g., on NFS
 
   gzip -d no longer segfaults on certain invalid inputs
diff --git a/gzip.c b/gzip.c
index fc2e7dcfa51c4a5013be40c6a52fac508cf674b0..8543128a909e4b156ecc4a14e979c8be21101137 100644 (file)
--- a/gzip.c
+++ b/gzip.c
@@ -650,6 +650,7 @@ local void treat_stdin()
     clear_bufs(); /* clear input and output buffers */
     to_stdout = 1;
     part_nb = 0;
+    ifd = fileno(stdin);
 
     if (decompress) {
        method = get_method(ifd);