Date: Fri, 10 Mar 2017 16:04:00 +0000 (UTC) From: Jilles Tjoelker <jilles@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r315005 - in head/bin/sh: . tests/expansion Message-ID: <201703101604.v2AG40b6021069@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jilles Date: Fri Mar 10 16:04:00 2017 New Revision: 315005 URL: https://svnweb.freebsd.org/changeset/base/315005 Log: sh: Fix executing wrong command with ${unsetvar#$(cmdsubst)}$(cmdsubst). 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". MFC after: 1 week Added: head/bin/sh/tests/expansion/cmdsubst23.0 (contents, props changed) Modified: head/bin/sh/expand.c head/bin/sh/tests/expansion/Makefile Modified: head/bin/sh/expand.c ============================================================================== --- head/bin/sh/expand.c Fri Mar 10 14:44:59 2017 (r315004) +++ head/bin/sh/expand.c Fri Mar 10 16:04:00 2017 (r315005) @@ -769,8 +769,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: head/bin/sh/tests/expansion/Makefile ============================================================================== --- head/bin/sh/tests/expansion/Makefile Fri Mar 10 14:44:59 2017 (r315004) +++ head/bin/sh/tests/expansion/Makefile Fri Mar 10 16:04:00 2017 (r315005) @@ -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 Added: head/bin/sh/tests/expansion/cmdsubst23.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/bin/sh/tests/expansion/cmdsubst23.0 Fri Mar 10 16:04:00 2017 (r315005) @@ -0,0 +1,5 @@ +# $FreeBSD$ + +unset n +x=abcd +[ "X${n#$(echo a)}X${x#$(echo ab)}X$(echo abc)X" = XXcdXabcX ]
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201703101604.v2AG40b6021069>