[PATCH 04/12] Fix up various problems in netbug script.

Andreas Henriksson
2007-10-12T08:57:36Z

From: Javier FernÃ¡ndez-Sanguino PeÃ±a <jfs@computer.org>

Fix race conditions and temporary file symlink attacks.
See http://bugs.debian.org/289541

Additional improvements by Allard Hoeve <allard@byte.nl> and others.
See http://bugs.debian.org/313540, http://bugs.debian.org/313541,
and http://bugs.debian.org/313544.

Signed-off-by: Andreas Henriksson <andreas@fatal.se>
---
misc/netbug | 24 ++++++++----------------
1 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/misc/netbug b/misc/netbug
index 6d13c8e..7b6ecea 100644
--- a/misc/netbug
+++ b/misc/netbug
@@ -1,23 +1,16 @@
#! /bin/bash

+set -e
+
echo -n "Send network configuration summary to [ENTER means kuznet@ms2.inr.ac.ru] "
IFS="" read mail || exit 1
[ -z "$mail" ] && mail=kuznet@ms2.inr.ac.ru

+netbug=`mktemp -d -t netbug.XXXXXX` || (echo "$0: Cannot create temporary directory" >&2; exit 1; )
+netbugtar=`tempfile -d $netbug --suffix=tar.gz` || (echo "$0: Cannot create temporary file" >&2; exit 1; )
+tmppath=$netbug
+trap "/bin/rm -rf $netbug $netbugtar" 0 1 2 3 13 15

-netbug=""
-while [ "$netbug" = "" ]; do
- netbug=`echo netbug.$$.$RANDOM`
- if [ -e /tmp/$netbug ]; then
- netbug=""
- fi
-done
-
-tmppath=/tmp/$netbug
-
-trap "rm -rf $tmppath $tmppath.tar.gz" 0 SIGINT
-
-mkdir $tmppath
mkdir $tmppath/net

cat /proc/slabinfo > $tmppath/slabinfo
@@ -44,9 +37,8 @@ if [ -e /proc/net/tcp6 ]; then
fi

cd /tmp
-tar c $netbug | gzip -9c > $netbug.tar.gz
-
-uuencode $netbug.tar.gz $netbug.tar.gz | mail -s $netbug "$mail"
+tar c $tmppath | gzip -9c > $netbugtar
+uuencode $netbugtar $netbugtar | mail -s $netbug "$mail"

echo "Sending to <$mail>; subject is $netbug"

--
1.5.3.4