Skip to contentSkip to conversation

work around an obnoxious bash "safety feature" on OpenBSD

PATCH In review Junio C Hamano 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 work around an obnoxious bash "safety feature" on OpenBSD

Bash (4.0.24) on OpenBSD 4.6 refuses to run this snippet:

    $ cat gomi.sh
    #!/bin/sh
    one="/var/tmp/1 1"
    rm -f /var/tmp/1 "/var/tmp/1 1"
    echo hello >$one
    $ sh gomi.sh; ls /var/tmp/1*
    /var/tmp/1 1
    $ bash gomi.sh; ls /var/tmp/1*
    gomi.sh: line 4: $one: ambiguous redirect
    ls: /var/tmp/1*: No such file or directory

Every competent shell programmer knows that a <$word in redirection is not subject to field splitting (POSIX.1 "2.7 Redirection" explicitly lists the kind of expansion performed: "... the word that follows the redirection operator shall be subjected to ...", and "Field Splitting" is not among them).

Some clueless folks apparently decided that users need to be protected in the name of "security", however.

Output from "git grep -e '> *\$' -- '*.sh'" indicates that rebase-i suffers from this bogus "safety". Work it around by surrounding the variable reference with a dq pair.

---

* I don't regularly run OpenBSD and build test on the platform only occasionally. People who _do_ care about the platform perhaps need to run the testsuite to find and help fixing other possible issues.

You will trigger this the path to your git work tree has whitespace in it, e.g. t3404.

 git-rebase--interactive.sh |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
git-rebase--interactive.sh +5 -4
index 19a608c..cecaa1d 100755
@@ -368,7 +368,8 @@ nth_string () {
 }
 
 update_squash_messages () {
-	if test -f "$SQUASH_MSG"; then
+	if test -f "$SQUASH_MSG"
+	then
 		mv "$SQUASH_MSG" "$SQUASH_MSG".bak || exit
 		COUNT=$(($(sed -n \
 			-e "1s/^# This is a combination of \(.*\) commits\./\1/p" \
@@ -378,7 +379,7 @@ update_squash_messages () {
 			sed -e 1d -e '2,/^./{
 				/^$/d
 			}' <"$SQUASH_MSG".bak
-		} >$SQUASH_MSG
+		} >"$SQUASH_MSG"
 	else
 		commit_message HEAD > "$FIXUP_MSG" || die "Cannot write $FIXUP_MSG"
 		COUNT=2
@@ -387,7 +388,7 @@ update_squash_messages () {
 			echo "# The first commit's message is:"
 			echo
 			cat "$FIXUP_MSG"
-		} >$SQUASH_MSG
+		} >"$SQUASH_MSG"
 	fi
 	case $1 in
 	squash)
@@ -403,7 +404,7 @@ update_squash_messages () {
 		echo
 		commit_message $2 | sed -e 's/^/#	/'
 		;;
-	esac >>$SQUASH_MSG
+	esac >>"$SQUASH_MSG"
 }
 
 peek_next_command () {
#1 lore raw

git-rebase--interactive.sh nth_string () { · line 372

Quoted 4 lines · Junio C Hamano

update_squash_messages () {

git-rebase--interactive.sh +2 -1
-	if test -f "$SQUASH_MSG"; then
+	if test -f "$SQUASH_MSG"
+	then

I don't think this belongs here.

Jeff

#2 lore raw
Quoted 9 lines · Jeff Epler

git-rebase--interactive.sh nth_string () { · line 372

Quoted 4 lines · Junio C Hamano

update_squash_messages () {

git-rebase--interactive.sh +2 -1
-	if test -f "$SQUASH_MSG"; then
+	if test -f "$SQUASH_MSG"
+	then

I don't think this belongs here.

Jeff

Yeah, it is a general improvement in the vicinity.