From: Bruno Haible Date: Fri, 14 Jan 2005 12:25:38 +0000 (+0000) Subject: Use a more secure way to create temporary files and directories. X-Git-Tag: v0.14.2~134 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6a7a9859901391991b81817eb643bab308e6503a;p=thirdparty%2Fgettext.git Use a more secure way to create temporary files and directories. --- diff --git a/gettext-tools/lib/ChangeLog b/gettext-tools/lib/ChangeLog index c4802dbf6..2534dfc1c 100644 --- a/gettext-tools/lib/ChangeLog +++ b/gettext-tools/lib/ChangeLog @@ -1,3 +1,8 @@ +2005-01-09 Bruno Haible + + * csharpcomp.sh.in (func_tmpdir): New function. + (mcs invocation): Use it. Fix exit code. + 2005-01-07 Bruno Haible * csharpcomp.c: Include safe-read.h. diff --git a/gettext-tools/misc/ChangeLog b/gettext-tools/misc/ChangeLog index c28159c4a..ec4bef281 100644 --- a/gettext-tools/misc/ChangeLog +++ b/gettext-tools/misc/ChangeLog @@ -1,3 +1,12 @@ +2005-01-09 Bruno Haible + + * 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 . + 2005-01-05 Bruno Haible * autopoint.in: Update year in --version output. diff --git a/gettext-tools/misc/autopoint.in b/gettext-tools/misc/autopoint.in index 0e9a47c8a..7c4d40fc1 100644 --- a/gettext-tools/misc/autopoint.in +++ b/gettext-tools/misc/autopoint.in @@ -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 diff --git a/gettext-tools/misc/gettextize.in b/gettext-tools/misc/gettextize.in index 09f890d23..aefba8867 100644 --- a/gettext-tools/misc/gettextize.in +++ b/gettext-tools/misc/gettextize.in @@ -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