From: Paul Eggert Date: Sun, 24 Dec 2006 04:14:57 +0000 (+0000) Subject: * zdiff.in: Fix typo that broke most usages. Problem reported by X-Git-Tag: v1.3.12~25 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=be3ce2ded487aa2d3cdccefbca47ab6b72efbe60;p=debian%2Fgzip * zdiff.in: Fix typo that broke most usages. Problem reported by Jari Aalto in . While we're at it, fix a bunch of other problems. Handle "-" better. Send diagnostics to stderr, not stdout. Use expr rather than echo | sed, to handle special characters better. Report a diagnostic in the 1-arg case, if the argument doesn't end in .gz or the like, rather than having incomprehensible behavior. Do not require that the inputs be regular files. Avoid creating a temporary entirely, if /dev/fd works. If not, then resist denial-of-service attacks better, by using mktemp. * Makefile.am (gzip.doc.gz): New rule. (check-local): Depend on it, and test zdiff for Debian bug 404114. --- diff --git a/ChangeLog b/ChangeLog index 1536e72..1ba9221 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2006-12-23 Paul Eggert + + * zdiff.in: Fix typo that broke most usages. Problem reported by + Jari Aalto in . While we're at it, + fix a bunch of other problems. Handle "-" better. Send + diagnostics to stderr, not stdout. Use expr rather than echo | + sed, to handle special characters better. Report a diagnostic in + the 1-arg case, if the argument doesn't end in .gz or the like, + rather than having incomprehensible behavior. Do not require that + the inputs be regular files. Avoid creating a temporary entirely, + if /dev/fd works. If not, then resist denial-of-service attacks + better, by using mktemp. + * Makefile.am (gzip.doc.gz): New rule. + (check-local): Depend on it, and test zdiff for Debian bug 404114. + 2006-12-22 Paul Eggert * zdiff.1: Mention that these programs currently understand only diff --git a/Makefile.am b/Makefile.am index 917641d..6a72aee 100644 --- a/Makefile.am +++ b/Makefile.am @@ -48,6 +48,9 @@ gzip_LDADD = lib/libgzip.a gzip.doc: gzip.1 groff -man -Tascii $(srcdir)/gzip.1 | col -b | uniq >$@ +gzip.doc.gz: gzip.doc + gzip <$? >$@ + SUFFIXES = .in .in: sed \ @@ -60,7 +63,12 @@ SUFFIXES = .in # A simple test, just of gzip -- more of a sanity check than anything else. FILES_TO_CHECK = $(bin_SCRIPTS) $(gzip_LDADD) \ $(top_srcdir)/ChangeLog $(top_srcdir)/configure $(top_srcdir)/gzip.c -check-local: $(FILES_TO_CHECK) +check-local: $(FILES_TO_CHECK) gzip.doc.gz + ./zdiff -c gzip.doc.gz + ./zdiff -c gzip.doc gzip.doc + ./zdiff gzip.doc gzip.doc.gz + ./zdiff -c - gzip.doc &2 "$prog: $1: option contains apostrophe"; exit 2;; + -?*) cmp="$cmp '$1'"; shift;; + *) break;; esac done +cmp="$cmp --" + for file; do - test -f "$file" || { - echo "$prog: $file not found or not a regular file" - exit 2 - } + test "X$file" = X- || <"$file" || exit 2 done -if test $# -eq 1; then - FILE=`echo "$1" | sed 's/[-.][zZtga]*$//'` - gzip -cd -- "$1" | $comp $OPTIONS - "$FILE" +if test $# -eq 1; then + case $1 in + *[-.]gz* | *[-.][zZ] | *.t[ga]z) + FILE=`expr "X$1" : 'X\(.*\)[-.][zZtga]*$'` + gzip -cd -- "$1" | eval "$cmp" - '"$FILE"';; + *) + echo >&2 "$prog: $1: unknown compressed file extension" + exit 2;; + esac elif test $# -eq 2; then case "$1" in - *[-.]gz* | *[-.][zZ] | *.t[ga]z) + *[-.]gz* | *[-.][zZ] | *.t[ga]z | -) case "$2" in - *[-.]gz* | *[-.][zZ] | *.t[ga]z) - F=`echo "$2" | sed 's|.*/||;s|[-.][zZtga]*||'` - set -C - trap 'rm -f /tmp/"$F".$$; exit 2' HUP INT PIPE TERM 0 - gzip -cdfq -- "$2" > /tmp/"$F".$$ || exit - gzip -cdfq -- "$1" | $comp $OPTIONS - /tmp/"$F".$$ + *[-.]gz* | *[-.][zZ] | *.t[ga]z | -) + if test "$1$2" = --; then + gzip -cdfq - | eval "$cmp" - - + elif test -r /dev/fd/3 3/dev/null 2>&1; then + tmp=`mktemp -t -- "$F.XXXXXX"` || exit + else + set -C + tmp=${TMPDIR-/tmp}/$F.$$ + fi + gzip -cdfq -- "$2" > "$tmp" || exit + gzip -cdfq -- "$1" | eval "$cmp" - '"$tmp"' STAT="$?" - /bin/rm -f /tmp/"$F".$$ || STAT=2 + rm -f "$tmp" || STAT=2 trap - HUP INT PIPE TERM 0 - exit $STAT;; - - *) gzip -cdfq -- "$1" | $comp $OPTIONS - "$2";; + exit $STAT + fi;; + *) gzip -cdfq -- "$1" | eval "$cmp" - '"$2"';; esac;; *) case "$2" in - *[-.]gz* | *[-.][zZ] | *.t[ga]z) - gzip -cdfq -- "$2" | $comp $OPTIONS "$1" -;; - *) $comp $OPTIONS "$1" "$2";; + *[-.]gz* | *[-.][zZ] | *.t[ga]z | -) + gzip -cdfq -- "$2" | eval "$cmp" '"$1"' -;; + *) eval "$cmp" '"$1"' '"$2"';; esac;; esac else - echo "$usage" + echo >&2 "$usage" exit 2 fi