From: Javier Fernández-Sanguino Peña <[EMAIL PROTECTED]>

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

Additional improvements by Allard Hoeve <[EMAIL PROTECTED]> and others.
See http://bugs.debian.org/313540, http://bugs.debian.org/313541,
and http://bugs.debian.org/313544.

Signed-off-by: Andreas Henriksson <[EMAIL PROTECTED]>
---
 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 [EMAIL PROTECTED] "
 IFS="" read mail || exit 1
 [ -z "$mail" ] && [EMAIL PROTECTED]
 
+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

-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to