summaryrefslogtreecommitdiff
path: root/gnu/usr.bin
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2001-09-27 21:57:16 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2001-09-27 21:57:16 +0000
commit5cf1cd61e2ec1b6b3c2b649d39a70dd07db8a300 (patch)
tree4155ad2042de2192a04a947620c71878adf4808b /gnu/usr.bin
parent41cbc5d554dd669b6c4c5d18df51832b5edccc70 (diff)
Use mktemp(1) to avoid potential /tmp races
Diffstat (limited to 'gnu/usr.bin')
-rw-r--r--gnu/usr.bin/gzip/zdiff7
-rw-r--r--gnu/usr.bin/gzip/znew42
-rw-r--r--gnu/usr.bin/rcs/src/rcsfreeze.sh4
3 files changed, 30 insertions, 23 deletions
diff --git a/gnu/usr.bin/gzip/zdiff b/gnu/usr.bin/gzip/zdiff
index c2e21729a49..91cc50b4945 100644
--- a/gnu/usr.bin/gzip/zdiff
+++ b/gnu/usr.bin/gzip/zdiff
@@ -45,10 +45,11 @@ elif test $# -eq 2; then
case "$2" in
*[-.]gz* | *[-.][zZ] | *.t[ga]z)
F=`echo "$2" | sed 's|.*/||;s|[-.][zZtga]*||'`
- gzip -cdfq "$2" > /tmp/"$F".$$
- gzip -cdfq "$1" | $comp $OPTIONS - /tmp/"$F".$$
+ TF=`mktemp /tmp/"$F".XXXXXXXXXX` || exit 1
+ gzip -cdfq "$2" > $TF
+ gzip -cdfq "$1" | $comp $OPTIONS - $TF
STAT="$?"
- /bin/rm -f /tmp/"$F".$$;;
+ /bin/rm -f $TF;;
*) gzip -cdfq "$1" | $comp $OPTIONS - "$2"
STAT="$?";;
diff --git a/gnu/usr.bin/gzip/znew b/gnu/usr.bin/gzip/znew
index 95d61a2a719..c580e09f015 100644
--- a/gnu/usr.bin/gzip/znew
+++ b/gnu/usr.bin/gzip/znew
@@ -11,33 +11,39 @@ new=0
block=1024
# block is the disk block size (best guess, need not be exact)
+case "$GZIP" in
+ *-S*) ext=`echo "$GZIP" | sed 's/^.*-S[ ]*\([^ ]*\).*$/\1/'`
+ ;;
+ *-suffix*) ext=`echo "$GZIP" | sed 's/^.*--suffix[ =]*\([^ ]*\).*$/\1/'`
+ ;;
+ *) ext='.gz'
+ ;;
+esac
+if test "$ext" = ".Z"; then
+ echo znew: cannot use .Z as gzip extension.
+ exit 1
+fi
+
warn="(does not preserve modes and timestamp)"
-tmp=/tmp/zfoo.$$
-echo hi > $tmp.1
-echo hi > $tmp.2
-if test -z "`(${CPMOD-cpmod} $tmp.1 $tmp.2) 2>&1`"; then
+TMP1=`mktemp /tmp/zfoo.XXXXXXXXXX` || exit 1
+TMP2=`mktemp /tmp/zbar.XXXXXXXXXX`
+if [ $? -ne 0 ]; then
+ rm -f $TMP1
+ exit 1
+fi
+echo hi > $TMP1
+echo hi > $TMP2
+if test -z "`(${CPMOD-cpmod} $TMP1 $TMP2) 2>&1`"; then
cpmod=${CPMOD-cpmod}
warn=""
fi
-if test -z "$cpmod" && ${TOUCH-touch} -r $tmp.1 $tmp.2 2>/dev/null; then
+if test -z "$cpmod" && ${TOUCH-touch} -r $TMP1 $TMP2 2>/dev/null; then
cpmod="${TOUCH-touch}"
cpmodarg="-r"
warn="(does not preserve file modes)"
fi
-
-# check if GZIP env. variable uses -S or --suffix
-gzip -q $tmp.1
-ext=`echo $tmp.1* | sed "s|$tmp.1||"`
-rm -f $tmp.[12]*
-if test -z "$ext"; then
- echo znew: error determining gzip extension
- exit 1
-fi
-if test "$ext" = ".Z"; then
- echo znew: cannot use .Z as gzip extension.
- exit 1
-fi
+rm -f $TMP1 $TMP2
for arg
do
diff --git a/gnu/usr.bin/rcs/src/rcsfreeze.sh b/gnu/usr.bin/rcs/src/rcsfreeze.sh
index 44cfdb57bb5..5d147c73230 100644
--- a/gnu/usr.bin/rcs/src/rcsfreeze.sh
+++ b/gnu/usr.bin/rcs/src/rcsfreeze.sh
@@ -2,7 +2,7 @@
# rcsfreeze - assign a symbolic revision number to a configuration of RCS files
-# $Id: rcsfreeze.sh,v 1.2 1998/03/31 03:39:48 deraadt Exp $
+# $Id: rcsfreeze.sh,v 1.3 2001/09/27 21:57:15 millert Exp $
# The idea is to run rcsfreeze each time a new version is checked
# in. A unique symbolic revision number (C_[number], where number
@@ -56,7 +56,7 @@ rcsfreeze: give log message, summarizing changes (end with EOF or single '.')" \
# Stamp the logfile. Because we order the logfile the most recent
# first we will have to save everything right now in a temporary file.
-TMPLOG=/tmp/rcsfrz$$
+TMPLOG=`mktemp /tmp/rcsfrz.XXXXXXXXXX` || exit 1
trap 'rm -f $TMPLOG; exit 1' 1 2 13 15
# Now ask for a log message, continously add to the log file
(