aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Hutchings <ben@decadent.org.uk>2016-01-06 01:21:27 +0000
committerH. Peter Anvin <hpa@linux.intel.com>2016-01-05 17:51:26 -0800
commit0016a343f734cfe002dd45ab97a67b857ffe2e6d (patch)
tree732029c9471d3653ed834ce0949b4397e10b286b
parent5125a8b74971fc22fdc74cfc9dc8e04a4f5c0e4b (diff)
downloadklibc-0016a343f734cfe002dd45ab97a67b857ffe2e6d.tar.gz
[klibc] gzip: Fix silent fallback to decompression
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@decadent.org.uk> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
-rw-r--r--usr/gzip/gzip.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/usr/gzip/gzip.c b/usr/gzip/gzip.c
index ab73de01a875fb..d0c7e002a287e4 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.
*/