[PATCH] t0300-credentials: Word around a solaris /bin/sh bug

Subsystems: the rest

DORMANTno replies

5 messages, 4 authors, 2016-06-15 · open the first message on its own page

[PATCH] t0300-credentials: Word around a solaris /bin/sh bug

From: Ben Walton <hidden>
Date: 2016-06-15 22:52:55

Solaris' /bin/sh was making the IFS setting permanent instead of
temporary when using it to slurp in credentials in the generated
'dump' script of the 'setup helper scripts' test in t0300-credentials.

The stderr file that was being compared to expected-stderr contained the
following stray line from the credential helper run:

warning: invalid credential line: username foo

To avoid this bug, capture the original IFS and force it to be reset
after its use is no longer required.  For now, this is lighter weight
than altering which shell these scripts use as their shebang.

Signed-off-by: Ben Walton <redacted>
---
 t/t0300-credentials.sh |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh
index 885af8f..1be3fe2 100755
--- a/t/t0300-credentials.sh
+++ b/t/t0300-credentials.sh
@@ -8,10 +8,12 @@ test_expect_success 'setup helper scripts' '
 	cat >dump <<-\EOF &&
 	whoami=`echo $0 | sed s/.*git-credential-//`
 	echo >&2 "$whoami: $*"
+	OIFS=$IFS
 	while IFS== read key value; do
 		echo >&2 "$whoami: $key=$value"
 		eval "$key=$value"
 	done
+	IFS=$OIFS
 	EOF
 
 	cat >git-credential-useless <<-\EOF &&
-- 
1.7.8.3

Re: [PATCH] t0300-credentials: Word around a solaris /bin/sh bug

From: Frans Klaver <hidden>
Date: 2016-06-15 22:52:55

Wor_k_ around ...


On Thu, 02 Feb 2012 20:32:15 +0100, Ben Walton  
[off-list ref] wrote:
quoted hunk
Solaris' /bin/sh was making the IFS setting permanent instead of
temporary when using it to slurp in credentials in the generated
'dump' script of the 'setup helper scripts' test in t0300-credentials.

The stderr file that was being compared to expected-stderr contained the
following stray line from the credential helper run:

warning: invalid credential line: username foo

To avoid this bug, capture the original IFS and force it to be reset
after its use is no longer required.  For now, this is lighter weight
than altering which shell these scripts use as their shebang.

Signed-off-by: Ben Walton <redacted>
---
 t/t0300-credentials.sh |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh
index 885af8f..1be3fe2 100755
--- a/t/t0300-credentials.sh
+++ b/t/t0300-credentials.sh
@@ -8,10 +8,12 @@ test_expect_success 'setup helper scripts' '
 	cat >dump <<-\EOF &&
 	whoami=`echo $0 | sed s/.*git-credential-//`
 	echo >&2 "$whoami: $*"
+	OIFS=$IFS
 	while IFS== read key value; do
 		echo >&2 "$whoami: $key=$value"
 		eval "$key=$value"
 	done
+	IFS=$OIFS
 	EOF
	cat >git-credential-useless <<-\EOF &&

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Re: [PATCH] t0300-credentials: Word around a solaris /bin/sh bug

From: Ben Walton <hidden>
Date: 2016-06-15 22:52:55

Excerpts from Frans Klaver's message of Thu Feb 02 14:44:08 -0500 2012:
Wor_k_ around ...
*face*palm*

Thanks for catching that.

Junio, can you make that tweak if the patch is ok or would you prefer
a new mail?

Thanks
-Ben
--
Ben Walton
Systems Programmer - CHASS
University of Toronto
C:416.407.5610 | W:416.978.4302

Re: [PATCH] t0300-credentials: Word around a solaris /bin/sh bug

From: Jeff King <hidden>
Date: 2016-06-15 22:52:55

On Thu, Feb 02, 2012 at 02:32:15PM -0500, Ben Walton wrote:
Solaris' /bin/sh was making the IFS setting permanent instead of
temporary when using it to slurp in credentials in the generated
'dump' script of the 'setup helper scripts' test in t0300-credentials.
Hmm. Presumably you are setting SHELL_PATH, as Solaris /bin/sh would be
useless for running the rest of the tests. Usually scripts inside the
tests use #!$SHELL_PATH, but I often don't bother if it's a simple "even
Solaris /bin/sh could run this" script. But in this case I either
underestimated the complexity of my script or overestimated the quality
of the Solaris /bin/sh.

I wonder if a better solution is to use a known-good shell instead of
trying to work around problems in a bogus shell. Does the patch below
fix it for you?
diff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh
index 885af8f..edf6547 100755
--- a/t/t0300-credentials.sh
+++ b/t/t0300-credentials.sh
@@ -14,15 +14,15 @@ test_expect_success 'setup helper scripts' '
 	done
 	EOF
 
-	cat >git-credential-useless <<-\EOF &&
-	#!/bin/sh
+	cat >git-credential-useless <<-EOF &&
+	#!$SHELL_PATH
 	. ./dump
 	exit 0
 	EOF
 	chmod +x git-credential-useless &&
 
-	cat >git-credential-verbatim <<-\EOF &&
-	#!/bin/sh
+	echo "#!$SHELL_PATH" >git-credential-verbatim &&
+	cat >>git-credential-verbatim <<-\EOF &&
 	user=$1; shift
 	pass=$1; shift
 	. ./dump

Re: [PATCH] t0300-credentials: Word around a solaris /bin/sh bug

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:52:55

Ben Walton wrote:
quoted hunk
--- a/t/t0300-credentials.sh
+++ b/t/t0300-credentials.sh
@@ -8,10 +8,12 @@ test_expect_success 'setup helper scripts' '
 	cat >dump <<-\EOF &&
 	whoami=`echo $0 | sed s/.*git-credential-//`
 	echo >&2 "$whoami: $*"
+	OIFS=$IFS
 	while IFS== read key value; do
 		echo >&2 "$whoami: $key=$value"
 		eval "$key=$value"
 	done
+	IFS=$OIFS
Oh, good catch.  Technically "read" is not a special builtin so POSIX shells
are not supposed to do this (and Jeff's patch definitely looks right), but in
any case temporary variable settings while running a builtin are close
enough to the assignment-during-special-builtin-or-function case to
make me shiver a little. ;-)

Would something like

	(
		IFS==
		while read key value
		do
			...
		done
	)

make sense?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help