svn commit: r315486 - in stable/11/bin/sh: . tests/expansion
Jilles Tjoelker
jilles at FreeBSD.org
Sat Mar 18 16:07:30 UTC 2017
Author: jilles
Date: Sat Mar 18 16:07:28 2017
New Revision: 315486
URL: https://svnweb.freebsd.org/changeset/base/315486
Log:
MFC r315005: sh: Fix executing wrong command with ${x#$(y)}$(z).
The parsed internal representation of words consists of a byte string with a
list of nodes (commands in command substitution). Each unescaped CTLBACKQ or
CTLBACKQ | CTLQUOTE byte corresponds to an entry in the list.
If param in ${param#%##%%word} is not set, the word is not expanded (in a
deviation of POSIX shared with other ash variants and ksh93). Erroneously,
the pointer in the list of commands (argbackq) was not advanced. This caused
the wrong command to be executed later if the outer word contained another
command substitution.
Example:
echo "${unsetvar#$(echo a)}$(echo b)"
wrote "a" but should write "b".
Added:
stable/11/bin/sh/tests/expansion/cmdsubst23.0
- copied unchanged from r315005, head/bin/sh/tests/expansion/cmdsubst23.0
Modified:
stable/11/bin/sh/expand.c
stable/11/bin/sh/tests/expansion/Makefile
Directory Properties:
stable/11/ (props changed)
Modified: stable/11/bin/sh/expand.c
==============================================================================
--- stable/11/bin/sh/expand.c Sat Mar 18 15:42:22 2017 (r315485)
+++ stable/11/bin/sh/expand.c Sat Mar 18 16:07:28 2017 (r315486)
@@ -768,8 +768,10 @@ again: /* jump here after setting a vari
case VSTRIMLEFTMAX:
case VSTRIMRIGHT:
case VSTRIMRIGHTMAX:
- if (!set)
+ if (!set) {
+ set = 1;
break;
+ }
/*
* Terminate the string and start recording the pattern
* right after it
Modified: stable/11/bin/sh/tests/expansion/Makefile
==============================================================================
--- stable/11/bin/sh/tests/expansion/Makefile Sat Mar 18 15:42:22 2017 (r315485)
+++ stable/11/bin/sh/tests/expansion/Makefile Sat Mar 18 16:07:28 2017 (r315486)
@@ -44,6 +44,7 @@ ${PACKAGE}FILES+= cmdsubst19.0
${PACKAGE}FILES+= cmdsubst20.0
${PACKAGE}FILES+= cmdsubst21.0
${PACKAGE}FILES+= cmdsubst22.0
+${PACKAGE}FILES+= cmdsubst23.0
${PACKAGE}FILES+= export1.0
${PACKAGE}FILES+= export2.0
${PACKAGE}FILES+= export3.0
Copied: stable/11/bin/sh/tests/expansion/cmdsubst23.0 (from r315005, head/bin/sh/tests/expansion/cmdsubst23.0)
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ stable/11/bin/sh/tests/expansion/cmdsubst23.0 Sat Mar 18 16:07:28 2017 (r315486, copy of r315005, head/bin/sh/tests/expansion/cmdsubst23.0)
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+unset n
+x=abcd
+[ "X${n#$(echo a)}X${x#$(echo ab)}X$(echo abc)X" = XXcdXabcX ]
More information about the svn-src-stable
mailing list