klibc-bot for Ben Hutchings
2016-Jan-06 01:54 UTC
[klibc] [klibc:master] gzip: Fix silent fallback to decompression
Commit-ID: 0016a343f734cfe002dd45ab97a67b857ffe2e6d Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=0016a343f734cfe002dd45ab97a67b857ffe2e6d Author: Ben Hutchings <ben at decadent.org.uk> AuthorDate: Wed, 6 Jan 2016 01:21:27 +0000 Committer: H. Peter Anvin <hpa at linux.intel.com> CommitDate: Tue, 5 Jan 2016 17:51:26 -0800 [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 at decadent.org.uk> Signed-off-by: H. Peter Anvin <hpa at linux.intel.com> --- 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. */