2074N/AFrom b3b5611e046b93fb20aa783d6d11d986f33f91f6 Mon Sep 17 00:00:00 2001
2074N/ADate: Thu, 3 Oct 2013 21:12:09 -0700
2074N/ASubject: [PATCH] znew: avoid denial-of-service issue
2074N/A*
znew.in: Rewrite to avoid the need for a temporary file in /tmp.
2074N/AThat way, we avoid the need for set -C
2074N/Aand worrying about denial of service.
2074N/AUse touch -r and chmod --reference rather than cpmod.
2074N/AAssume cp -p works, as it's now universal.
2074N/AQuote 'echo' args better, while we're at it.
2074N/A(warn, tmp, cpmod, cpmodarg): Remove.
2074N/A(GZIP): Unset, so that we needn't test for gzip extension.
2074N/A* znew.1: Document the change of implementation assumptions.
2074N/Aindex dcdf84f..2a7e5e1 100644
2074N/A@@ -32,9 +32,16 @@ Keep a .Z file when it is smaller than the .gz file; implies
2074N/A gzip(1), zmore(1), zdiff(1), zgrep(1), zforce(1), gzexe(1), compress(1)
2074N/A-does not maintain the time stamp with the -P option if
2074N/A-does not support the -r option.
2074N/A+does not maintain the time stamp if
+option, and does not maintain permissions if
# block is the disk block size (best guess, need not be exact)
-warn="(does not preserve modes and timestamp)"
-if test -z "`(${CPMOD-cpmod} $tmp $tmp) 2>&1`"; then
-if test -z "$cpmod" && ${TOUCH-touch} -r $tmp $tmp 2>
/dev/null; then
- warn="(does not preserve file modes)"
-# check if GZIP env. variable uses -S or --suffix
-ext=`echo $tmp* | sed "s|$tmp||"`
- echo znew: error determining gzip extension
-if test "$ext" = ".Z"; then
- echo znew: cannot use .Z as gzip extension.
+# Beware -s or --suffix in $GZIP.
@@ -116,26 +92,27 @@ if test -n "$opt"; then
- n=`echo $i | sed 's/.Z$//'`
+ n=`echo "$i" | sed 's/.Z$//'`
if test ! -f "$
n.Z" ; then
test $keep -eq 1 && old=`wc -c < "$
n.Z"`
if test $pipe -eq 1; then
if gzip -d < "$
n.Z" | gzip $opt > "$n$ext"; then
# Copy file attributes from old file to new one, if possible.
- test -n "$cpmod" && $cpmod $cpmodarg "$
n.Z" "$n$ext" 2>
/dev/null- echo error while recompressing $
n.Z+ echo "error while recompressing $
n.Z"
if test $check -eq 1; then
+ if cp -p "$
n.Z" "$n.$$"; then
- echo cannot backup "$
n.Z"
+ echo "cannot backup $
n.Z"
@@ -143,7 +120,7 @@ for i do
test $check -eq 1 && mv "$n.$$" "$
n.Z"
- echo error while uncompressing $
n.Z+ echo "error while uncompressing $
n.Z"
@@ -151,10 +128,10 @@ for i do
if test $check -eq 1; then
mv "$n.$$" "$
n.Z" && rm -f "$n"
- echo error while recompressing $n
+ echo "error while recompressing $n"
# compress $n (might be dangerous if disk full)
- echo error while recompressing $n, left uncompressed
+ echo "error while recompressing $n, left uncompressed"
@@ -175,7 +152,7 @@ for i do
test $pipe -eq 0 && mv "$n.$$" "$
n.Z"
- echo error while testing $n$ext, $
n.Z unchanged
+ echo "error while testing $n$ext, $
n.Z unchanged"
elif test $pipe -eq 1; then