Switch from using /tmp to using mktemp

mktemp protects against attacks from other users.
mktemp protects against concurrent writers.
mktemp respects the $TMPDIR environment variable.

Suggested-by: check-all-the-things
This commit is contained in:
Paul Wise 2019-09-04 20:36:20 +08:00
parent a85d5f57bb
commit 1d7d4c2446
No known key found for this signature in database
GPG key ID: 3116BA5E9FFA69A3
2 changed files with 8 additions and 6 deletions

View file

@ -37,10 +37,11 @@ test -z $BRANCH && echo "branch argument required." 1>&2 && exit 1
if [[ -n $REMOTE ]] if [[ -n $REMOTE ]]
then then
git ls-remote --exit-code $REMOTE 1>/dev/null 2>/tmp/ls-remote-error stderr=$(git_extra_mktemp)
git ls-remote --exit-code $REMOTE 1>/dev/null 2>"$stderr"
REMOTE_EXIT=$? REMOTE_EXIT=$?
REMOTE_ERROR=$(</tmp/ls-remote-error) REMOTE_ERROR=$(<"$stderr")
rm -f /tmp/ls-remote-error rm -f "$stderr"
if [ $REMOTE_EXIT -eq 0 ] if [ $REMOTE_EXIT -eq 0 ]
then then
git push $REMOTE HEAD:refs/heads/$BRANCH git push $REMOTE HEAD:refs/heads/$BRANCH

View file

@ -9,13 +9,14 @@ make_install() {
fi fi
} }
cd /tmp \ dir=$(mktemp -t -d git-extras-install.XXXXXXXXXX) \
&& rm -rf ./git-extras \ && cd "$dir" \
&& echo "Setting up 'git-extras'...." \ && echo "Setting up 'git-extras'...." \
&& git clone https://github.com/tj/git-extras.git &> /dev/null \ && git clone https://github.com/tj/git-extras.git &> /dev/null \
&& cd git-extras \ && cd git-extras \
&& git checkout \ && git checkout \
$(git describe --tags $(git rev-list --tags --max-count=1)) \ $(git describe --tags $(git rev-list --tags --max-count=1)) \
&> /dev/null \ &> /dev/null \
&& make_install && make_install \
&& rm -rf "$dir"