]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Use a more secure way to create temporary files and directories.
authorBruno Haible <bruno@clisp.org>
Fri, 14 Jan 2005 12:25:38 +0000 (12:25 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:12:04 +0000 (12:12 +0200)
gettext-tools/lib/ChangeLog
gettext-tools/misc/ChangeLog
gettext-tools/misc/autopoint.in
gettext-tools/misc/gettextize.in

index c4802dbf6ddf497f2c0ffdf2ee96aac4237e3597..2534dfc1c769277892469fc1a875b02f56044ab9 100644 (file)
@@ -1,3 +1,8 @@
+2005-01-09  Bruno Haible  <bruno@clisp.org>
+
+       * csharpcomp.sh.in (func_tmpdir): New function.
+       (mcs invocation): Use it. Fix exit code.
+
 2005-01-07  Bruno Haible  <bruno@clisp.org>
 
        * csharpcomp.c: Include safe-read.h.
index c28159c4aa072deae3427410e857c9ecb17d4fa0..ec4bef28182563c4dea93fd4f9d154518a2f86c1 100644 (file)
@@ -1,3 +1,12 @@
+2005-01-09  Bruno Haible  <bruno@clisp.org>
+
+       * autopoint.in (func_tmpdir): New function.
+       (func_find_curr_installdir): Use it.
+       (mismatchfile): Create inside a temporary directory. Remove afterwards.
+       * gettextize.in (func_tmpdir): New function.
+       (func_find_curr_installdir): Use it.
+       Reported by Joey Hess <joeyh@debian.org>.
+
 2005-01-05  Bruno Haible  <bruno@clisp.org>
 
        * autopoint.in: Update year in --version output.
index 0e9a47c8a651f30cda48a983ee8997908287080d..7c4d40fc1f7fa0bb4d046cbf1ba1f37e24c7faab 100644 (file)
@@ -30,6 +30,37 @@ version=@VERSION@
 prefix="@prefix@"
 gettext_dir="@datadir@/gettext"
 
+# func_tmpdir
+# creates a temporary directory.
+# Sets variable
+# - tmp             pathname of freshly created temporary directory
+func_tmpdir ()
+{
+  # Use the environment variable TMPDIR, falling back to /tmp. This allows
+  # users to specify a different temporary directory, for example, if their
+  # /tmp is filled up or too small.
+  : ${TMPDIR=/tmp}
+  {
+    # Use the mktemp program if available. If not available, hide the error
+    # message.
+    tmp=`(umask 077 && mktemp -d -q "$TMPDIR/gtXXXXXX") 2>/dev/null` &&
+    test -n "$tmp" && test -d "$tmp"
+  } ||
+  {
+    # Use a simple mkdir command. It is guaranteed to fail if the directory
+    # already exists.  $RANDOM is bash specific and expands to empty in shells
+    # other than bash, ksh and zsh.  Its use does not increase security;
+    # rather, it minimizes the probability of failure in a very cluttered /tmp
+    # directory.
+    tmp=$TMPDIR/gt$$-$RANDOM
+    (umask 077 && mkdir "$tmp")
+  } ||
+  {
+    echo "$0: cannot create a temporary directory in $TMPDIR" >&2
+    { (exit 1); exit 1; }
+  }
+}
+
 # Support for relocatability.
 func_find_curr_installdir ()
 {
@@ -39,14 +70,15 @@ func_find_curr_installdir ()
     */* | *\\*) ;;
     *) # Need to look in the PATH.
       if test "${PATH_SEPARATOR+set}" != set; then
-        { echo "#! /bin/sh"; echo "exit 0"; } > /tmp/conf$$.sh
-        chmod +x /tmp/conf$$.sh
-        if (PATH="/nonexistent;/tmp"; conf$$.sh) >/dev/null 2>&1; then
+        func_tmpdir
+        { echo "#! /bin/sh"; echo "exit 0"; } > "$tmp"/conf.sh
+        chmod +x "$tmp"/conf.sh
+        if (PATH="/nonexistent;$tmp"; conf.sh) >/dev/null 2>&1; then
           PATH_SEPARATOR=';'
         else
           PATH_SEPARATOR=:
         fi
-        rm -f /tmp/conf$$.sh
+        rm -f "$tmp"
       fi
       save_IFS="$IFS"; IFS="$PATH_SEPARATOR"
       for dir in $PATH; do
@@ -384,8 +416,8 @@ func_destfile ()
 # original - too great risk of version mismatch.
 if test -z "$force"; then
   mismatch=
-  mismatchfile="${TMPDIR-/tmp}"/autopoint$$.diff
-  rm -f "$mismatchfile"
+  func_tmpdir
+  mismatchfile="$tmp"/autopoint.diff
   for file in `find "$work_dir/archive" -type f -print | sed -e "s,^$work_dir/archive/,," | LC_ALL=C sort`; do
     func_destfile "$file"
     if test -n "$destfile"; then
@@ -404,6 +436,7 @@ if test -z "$force"; then
     rm -rf "$cvs_dir" "$work_dir"
     func_fatal_error "Some files have been locally modified. Not overwriting them because --force has not been specified. For your convenience, you find the local modifications in the file '$mismatchfile'."
   fi
+  rm -rf "$tmp"
 fi
 
 # func_mkdir_for to
index 09f890d23d275b86742c389034879398d93d3ad3..aefba8867336f10b86c9c0863eaf80976f279c83 100644 (file)
@@ -30,6 +30,37 @@ version=@VERSION@
 prefix="@prefix@"
 gettext_dir="@datadir@/gettext"
 
+# func_tmpdir
+# creates a temporary directory.
+# Sets variable
+# - tmp             pathname of freshly created temporary directory
+func_tmpdir ()
+{
+  # Use the environment variable TMPDIR, falling back to /tmp. This allows
+  # users to specify a different temporary directory, for example, if their
+  # /tmp is filled up or too small.
+  : ${TMPDIR=/tmp}
+  {
+    # Use the mktemp program if available. If not available, hide the error
+    # message.
+    tmp=`(umask 077 && mktemp -d -q "$TMPDIR/gtXXXXXX") 2>/dev/null` &&
+    test -n "$tmp" && test -d "$tmp"
+  } ||
+  {
+    # Use a simple mkdir command. It is guaranteed to fail if the directory
+    # already exists.  $RANDOM is bash specific and expands to empty in shells
+    # other than bash, ksh and zsh.  Its use does not increase security;
+    # rather, it minimizes the probability of failure in a very cluttered /tmp
+    # directory.
+    tmp=$TMPDIR/gt$$-$RANDOM
+    (umask 077 && mkdir "$tmp")
+  } ||
+  {
+    echo "$0: cannot create a temporary directory in $TMPDIR" >&2
+    { (exit 1); exit 1; }
+  }
+}
+
 # Support for relocatability.
 func_find_curr_installdir ()
 {
@@ -39,14 +70,15 @@ func_find_curr_installdir ()
     */* | *\\*) ;;
     *) # Need to look in the PATH.
       if test "${PATH_SEPARATOR+set}" != set; then
-        { echo "#! /bin/sh"; echo "exit 0"; } > /tmp/conf$$.sh
-        chmod +x /tmp/conf$$.sh
-        if (PATH="/nonexistent;/tmp"; conf$$.sh) >/dev/null 2>&1; then
+        func_tmpdir
+        { echo "#! /bin/sh"; echo "exit 0"; } > "$tmp"/conf.sh
+        chmod +x "$tmp"/conf.sh
+        if (PATH="/nonexistent;$tmp"; conf.sh) >/dev/null 2>&1; then
           PATH_SEPARATOR=';'
         else
           PATH_SEPARATOR=:
         fi
-        rm -f /tmp/conf$$.sh
+        rm -f "$tmp"
       fi
       save_IFS="$IFS"; IFS="$PATH_SEPARATOR"
       for dir in $PATH; do