]> thyrsus.com Git - src.git/commitdiff
srctest: use umask and mktemp for secure file names
authorMike Swanson <mikeonthecomputer@gmail.com>
Sat, 8 Nov 2014 22:28:10 +0000 (14:28 -0800)
committerEric S. Raymond <esr@thyrsus.com>
Sat, 8 Nov 2014 22:56:38 +0000 (17:56 -0500)
Just avoids some potential attacks from other users, either security
or simply messing up the testing.

srctest

diff --git a/srctest b/srctest
index 77641db270318aaf77fd961ebc8f0000a0059832..49a32afa84b521ebd44ce33b3dd40c46fadacd27 100755 (executable)
--- a/srctest
+++ b/srctest
@@ -3,8 +3,12 @@
 # Regression tester for SRC.
 #
 
-# Needs to not be a subdirectory of here, or git gets confused
-SANDBOX=/tmp/src-sandbox
+# Set the umask for a bit of defensiveness
+umask 0077
+
+# Needs to not be a subdirectory of here, or git gets confused.  Use
+# -u so that `src init` will work.
+SANDBOX=$(mktemp -u /tmp/.src_XXXXXXXX)
 
 trap "rm -fr testfile* testrev* newname* $SANDBOX" 0 1 2 15
 
@@ -17,8 +21,6 @@ check() {
 
 TESTOPTS="-T -S $SANDBOX $*"
 
-rm -fr $SANDBOX
-
 # Catches dumb and obvious case of code having a Python syntax error
 src $TESTOPTS init
 check "init"
@@ -195,4 +197,6 @@ EOF
 src $TESTOPTS ls | diff -u testfile16 -
 check "ls"
 
+rm -fr $SANDBOX
+
 # end