[klibc] [PATCH klibc] gzip: Fix silent fallback to decompression

Ben Hutchings ben at decadent.org.uk
Tue Jan 5 17:21:27 PST 2016


If the gzip utilities are built without support for compression,
they will always attempt to carry out decompression even if the
command name and options don't imply that.  Instead they should
fail with an explicit error in this case.

Signed-off-by: Ben Hutchings <ben at decadent.org.uk>
---
 usr/gzip/gzip.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/usr/gzip/gzip.c b/usr/gzip/gzip.c
index ab73de0..d0c7e00 100644
--- a/usr/gzip/gzip.c
+++ b/usr/gzip/gzip.c
@@ -90,8 +90,11 @@ int level = 6;        /* compression level */
 #endif
 
 int to_stdout;        /* output to stdout (-c) */
-#ifndef decompress
+#ifdef decompress
+int decompress_wanted;
+#else
 int decompress;       /* decompress (-d) */
+#define decompress_wanted decompress
 #endif
 int force;            /* don't ask questions, compress links (-f) */
 int no_name = -1;     /* don't save or restore the original file name */
@@ -259,17 +262,13 @@ int main (argc, argv)
      * Systems which do not support links can still use -d or -dc.
      * Ignore an .exe extension for MSDOS, OS/2 and VMS.
      */
-#ifndef decompress
     if (  strncmp(progname, "un",  2) == 0     /* ungzip, uncompress */
        || strncmp(progname, "gun", 3) == 0) {  /* gunzip */
-	decompress = 1;
+	decompress_wanted = 1;
     }
-#endif
     if (strequ(progname+1, "cat")       /* zcat, pcat, gcat */
 	|| strequ(progname, "gzcat")) {    /* gzcat */
-#ifndef decompress
-	decompress = 1;
-#endif
+	decompress_wanted = 1;
 	to_stdout = 1;
     }
 #endif
@@ -282,9 +281,7 @@ int main (argc, argv)
 	case 'c':
 	    to_stdout = 1; break;
 	case 'd':
-#ifndef decompress
-	    decompress = 1;
-#endif
+	    decompress_wanted = 1;
 	    break;
 	case 'f':
 	    force++; break;
@@ -308,9 +305,7 @@ int main (argc, argv)
             break;
 	case 't':
 	    test = to_stdout = 1;
-#ifndef decompress
-	    decompress = 1;
-#endif
+	    decompress_wanted = 1;
 	    break;
 	case 'v':
 	    verbose++; quiet = 0; break;
@@ -329,6 +324,14 @@ int main (argc, argv)
 	}
     } /* loop on all arguments */
 
+#ifndef SUPPORT_ZIP
+    if (!decompress_wanted) {
+	fprintf(stderr, "%s: this version does not support compression\n",
+		progname);
+	do_exit(ERROR);
+    }
+#endif
+
     /* By default, save name and timestamp on compression but do not
      * restore them on decompression.
      */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 811 bytes
Desc: Digital signature
URL: <http://www.zytor.com/pipermail/klibc/attachments/20160106/78d8ec92/attachment.sig>


More information about the klibc mailing list