Attached is a proposed patch to make the GZIP environment variable obsolescent,
for the same reason we're making GREP_OPTIONS obsolescent: it's too much
opportunity for trouble. For example, with a suitably crafted GZIP environment
variable I can cause 'gzip' to remove files.
>From 89eefaa9f9a47c98ef9ab4f0956221a8c21bb61f Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Fri, 13 Mar 2015 19:15:56 -0700
Subject: [PATCH] gzip: make the GZIP env var obsolescent
* NEWS, gzip.1:
* doc/gzip.texi (Environment, Tapes): Document it.
* gzip.c (main): Implement it.
---
NEWS | 5 +++++
doc/gzip.texi | 40 +++++++++++++++++-----------------------
gzip.1 | 42 +++++++++++++++++++++++++-----------------
gzip.c | 6 ++++++
4 files changed, 53 insertions(+), 40 deletions(-)
diff --git a/NEWS b/NEWS
index 4203f56..493df89 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,11 @@ GNU gzip NEWS -*- outline -*-
* Noteworthy changes in release ?.? (????-??-??) [?]
+** Changes in behavior
+
+ The GZIP environment variable is now obsolescent, and gzip now warns
+ if it is used. Please use an alias or script instead.
+
** Bug fixes
gzip -k -v no longer reports that files are replaced.
diff --git a/doc/gzip.texi b/doc/gzip.texi
index 2f4f1ab..eeb64ab 100644
--- a/doc/gzip.texi
+++ b/doc/gzip.texi
@@ -469,18 +469,25 @@ complement to @command{tar}, not as a replacement.
@chapter Environment
@cindex Environment
-The environment variable @env{GZIP} can hold a set of default options for
-@command{gzip}. These options are interpreted first and can be overwritten by
-explicit command line parameters. For example:
+The obsolescent environment variable @env{GZIP} can hold a set of
+default options for @command{gzip}. These options are interpreted
+first and can be overwritten by explicit command line parameters. As
+this can cause problems when using scripts, this feature will be
+removed in a future release of @command{gzip}, and @command{gzip}
+warns if it is used. Please use an alias or script instead. For
+example, if @command{gzip} is in the directory @samp{/usr/bin} you can
+prepend @file{$HOME/bin} to your @env{PATH} and create an executable
+script @file{$HOME/bin/gzip} containing the following:
@example
-for sh: GZIP="-8v --name"; export GZIP
-for csh: setenv GZIP "-8v --name"
-for MSDOS: set GZIP=-8v --name
+#! /bin/sh
+export PATH=/usr/bin
+exec gzip -v "$@@"
@end example
-On @abbr{VMS}, the name of the environment variable is @env{GZIP_OPT}, to
-avoid a conflict with the symbol set for invocation of the program.
+On @abbr{VMS}, the name of the obsolescent environment variable is
+@env{GZIP_OPT}, to avoid a conflict with the symbol set for invocation
+of the program.
@node Tapes
@chapter Using @command{gzip} on tapes
@@ -491,21 +498,8 @@ the output with zeroes up to a block boundary. When the data is read and
the whole block is passed to @command{gunzip} for decompression,
@command{gunzip} detects that there is extra trailing garbage after the
compressed data and emits a warning by default if the garbage contains
-nonzero bytes. You have to use the
-@option{--quiet} option to suppress the warning. This option can be set in the
-@env{GZIP} environment variable, as in:
-
-@example
-for sh: GZIP="-q" tar -xfz --block-compress /dev/rst0
-for csh: (setenv GZIP "-q"; tar -xfz --block-compress /dev/rst0)
-@end example
-
-In the above example, @command{gzip} is invoked implicitly by the @option{-z}
-option of @acronym{GNU} @command{tar}. Make sure that the same block
-size (@option{-b}
-option of @command{tar}) is used for reading and writing compressed data on
-tapes. (This example assumes you are using the @acronym{GNU} version of
-@command{tar}.)
+nonzero bytes. You can use the @option{--quiet} option to suppress
+the warning.
@node Problems
@chapter Reporting Bugs
diff --git a/gzip.1 b/gzip.1
index d81c45a..3aebae8 100644
--- a/gzip.1
+++ b/gzip.1
@@ -364,17 +364,34 @@ such as tar or zip. GNU tar supports the -z option to invoke gzip
transparently. gzip is designed as a complement to tar, not as a
replacement.
.SH "ENVIRONMENT"
-The environment variable
+The obsolescent environment variable
.B GZIP
can hold a set of default options for
.IR gzip .
These options are interpreted first and can be overwritten by
-explicit command line parameters. For example:
- for sh: GZIP="-8v --name"; export GZIP
- for csh: setenv GZIP "-8v --name"
- for MSDOS: set GZIP=-8v --name
+explicit command line parameters. As this can cause problems when
+using scripts, this feature will be removed in a future release of
+.IR gzip ,
+and
+.I gzip
+warns if it is used. Please use an alias or script instead. For
+example, if
+.I gzip
+is in the directory
+.B /usr/bin
+you can prepend
+.B $HOME/bin
+to your
+.B PATH
+and create an executable script
+.B $HOME/bin/gzip
+containing the following:
-On Vax/VMS, the name of the environment variable is GZIP_OPT, to
+ #! /bin/sh
+ export PATH=/usr/bin
+ exec gzip \-v "$@"
+
+On VMS, the name of the obsolescent environment variable is GZIP_OPT, to
avoid a conflict with the symbol set for invocation of the program.
.SH "SEE ALSO"
znew(1), zcmp(1), zmore(1), zforce(1), gzexe(1), zip(1), unzip(1), compress(1)
@@ -454,17 +471,8 @@ read and the whole block is passed to
for decompression,
.I gunzip
detects that there is extra trailing garbage after the compressed data
-and emits a warning by default. You have to use the --quiet option to
-suppress the warning. This option can be set in the
-.B GZIP
-environment variable as in:
- for sh: GZIP="-q" tar -xfz --block-compress /dev/rst0
- for csh: (setenv GZIP -q; tar -xfz --block-compr /dev/rst0
-
-In the above example, gzip is invoked implicitly by the -z option of
-GNU tar. Make sure that the same block size (-b option of tar) is used
-for reading and writing compressed data on tapes. (This example
-assumes you are using the GNU version of tar.)
+and emits a warning by default. You can use the --quiet option to
+suppress the warning.
.SH BUGS
The gzip format represents the input size modulo 2^32, so the
--list option reports incorrect uncompressed sizes and compression
diff --git a/gzip.c b/gzip.c
index e69c3e0..5536d6d 100644
--- a/gzip.c
+++ b/gzip.c
@@ -531,6 +531,12 @@ int main (int argc, char **argv)
file_count = argc - optind;
+ if (args)
+ WARN ((stderr,
+ ("%s: warning: "OPTIONS_VAR" environ var is deprecated; "
+ "please use an alias or script\n"),
+ program_name));
+
#if O_BINARY
#else
if (ascii && !quiet) {
--
2.1.0