gzip: fix a data-loss bug when decompressing with --suffix=''
authorJim Meyering <meyering@redhat.com>
Sat, 20 Feb 2010 10:07:55 +0000 (11:07 +0100)
committerJim Meyering <meyering@redhat.com>
Mon, 22 Feb 2010 13:42:54 +0000 (14:42 +0100)
* gzip.c (main): Disallow an empty --suffix=S also with -d.
Otherwise, "gzip -d -S '' F.gz" would ask if it's ok to remove the
existing file, "F.gz";  if you reply "yes", you'd lose all of that data.
Use of an empty suffix was already rejected in compression mode.
* gzip.1 (--suffix (-S)): Do not recommend to use "gunzip -S '' *".
Describe how the suffix is used when decompressing, too.
* NEWS (Bug fixes): mention the fix.
Reported by Ripduman Sohan.

NEWS
THANKS
gzip.1
gzip.c

diff --git a/NEWS b/NEWS
index 9c248f1ec252706e5069be810aefae0856ec3311..7a98c4999bcde3bb7ce9eebd7e4fe88f343e10cf 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,12 @@ GNU gzip NEWS                                    -*- outline -*-
 
 ** Bug fixes
 
+  "gzip -d -S '' precious.gz" is now rejected immediately.  Before,
+  that command would emulate "rm -i precious.gz", but with an easily-
+  misunderstood prompt.  I.e., gzip would ask if it's ok to remove the
+  existing file, "precious.gz".  If you made the mistake of saying "yes",
+  it would remove that input file before attempting to uncompress it.
+
   gzip -cdf now properly handles input consisting of gzip'd data followed
   by uncompressed data.  Before it would output raw compressed input, too.
   For example, now "(printf x|gzip; echo y)|gzip -dcf" prints "xy\n",
diff --git a/THANKS b/THANKS
index 183d39ce9f71e96594d9c1ed0496b28c8a9f3342..b0833e5f124590583430145e7987b5e4a6400acf 100644 (file)
--- a/THANKS
+++ b/THANKS
@@ -237,6 +237,7 @@ Amos Shapira            amoss@cs.huji.ac.il
 Rick Sladkey            jrs@world.std.com
 Daniel L Smith          dls@autodesk.com
 Fred Smith              fredex%fcshome@merk.merk.com
+Ripduman Sohan          Ripduman.Sohan@cl.cam.ac.uk
 Stephen Soliday         soliday@ncat.edu
 Paul Southworth         pauls@css.itd.umich.edu
 Rob Spencer             robbie@winkle.bhpese.oz.au
diff --git a/gzip.1 b/gzip.1
index bdf69435c8c9ade9141b038a81e1445a82e898c0..8db327d58c82924694ba4cf0a19a501bcc89ceb7 100644 (file)
--- a/gzip.1
+++ b/gzip.1
@@ -291,15 +291,14 @@ will descend into the directory and compress all the files it finds there
 ).
 .TP
 .B \-S .suf   --suffix .suf
-Use suffix .suf instead of .gz. Any suffix can be given, but suffixes
+When compressing, use suffix .suf instead of .gz.
+Any non-empty suffix can be given, but suffixes
 other than .z and .gz should be avoided to avoid confusion when files
-are transferred to other systems.  A null suffix forces gunzip to  try
-decompression on all given files regardless of suffix, as in:
+are transferred to other systems.
 
-    gunzip -S "" *       (*.* for MSDOS)
+When decompressing, add .suf to the beginning of the list of
+suffixes to try, when deriving an output file name from an input file name.
 
-Previous versions of gzip used
-the .z suffix. This was changed to avoid a conflict with
 .IR pack "(1)".
 .TP
 .B \-t --test
diff --git a/gzip.c b/gzip.c
index 66cb80436e59326aa104208cafcb0c2b59cad1d9..d1105e56b5781b8538eacd9fe40cf8b42a2276c9 100644 (file)
--- a/gzip.c
+++ b/gzip.c
@@ -543,11 +543,11 @@ int main (int argc, char **argv)
                 program_name);
     }
 #endif
-    if ((z_len == 0 && !decompress) || z_len > MAX_SUFFIX) {
-        fprintf(stderr, "%s: incorrect suffix '%s'\n",
-                program_name, z_suffix);
+    if (z_len == 0 || z_len > MAX_SUFFIX) {
+        fprintf(stderr, "%s: invalid suffix '%s'\n", program_name, z_suffix);
         do_exit(ERROR);
     }
+
     if (do_lzw && !decompress) work = lzw;
 
     /* Allocate all global buffers (for DYN_ALLOC option) */