[PATCH] tmp races in makeself

Ludwig Nussel ludwig.nussel at gmx.de
Sun Sep 5 16:51:18 EDT 2004


Hi,

makeself contains two tmp races. One on a file when --copy is used
and the other because mkdir -p doesn't fail if the directory already
exists. Ideally one would use the mktemp command but that's not
available everywhere.

cu
Ludwig

-- 
(o_  Ludwig.Nussel at gmx.de
//\  PGP Key ID: FF8135CE
V_/_ ICQ:        52166811
-------------- next part --------------
Index: loki_setup/makeself/makeself-header.sh
===================================================================
--- loki_setup.orig/makeself/makeself-header.sh
+++ loki_setup/makeself/makeself-header.sh
@@ -254,7 +254,12 @@ done
 
 case "\$copy" in
 copy)
-    SCRIPT_COPY="\$TMPROOT/makeself\$\$"
+    tmpdir=\$TMPROOT/makeself.\$RANDOM.\$\$
+    mkdir "\$tmpdir" || {
+	echo "Could not create temporary directory \$tmpdir" >&2
+	exit 1
+    }
+    SCRIPT_COPY="\$tmpdir/makeself"
     echo "Copying to a temporary location..." >&2
     cp "\$0" "\$SCRIPT_COPY"
     chmod +x "\$SCRIPT_COPY"
@@ -262,7 +267,7 @@ copy)
     exec "\$SCRIPT_COPY" --phase2
     ;;
 phase2)
-    finish="\$finish ; rm -f \$0"
+    finish="\$finish ; rm -rf \`dirname \$0\`"
     ;;
 esac
 
@@ -297,9 +302,9 @@ else
 	echo "Creating directory \$targetdir" >&2
 	tmpdir="\$targetdir"
     else
-	tmpdir="\$TMPROOT/selfgz\$\$"
+	tmpdir="\$TMPROOT/selfgz.\$RANDOM.\$\$"
     fi
-    mkdir -p \$tmpdir || {
+    mkdir \$tmpdir || {
 	echo 'Cannot create target directory' \$tmpdir >&2
 	echo 'You should try option --target OtherDirectory' >&2
 	eval \$finish
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://icculus.org/pipermail/lokisetup/attachments/20040905/d8d3a591/attachment.pgp>


More information about the Lokisetup mailing list