From owner-svn-src-stable@freebsd.org Fri Jun 30 21:32:50 2017 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2ADA7D9AF2F; Fri, 30 Jun 2017 21:32:50 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 002267D919; Fri, 30 Jun 2017 21:32:49 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v5ULWn0m030248; Fri, 30 Jun 2017 21:32:49 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v5ULWmg0030245; Fri, 30 Jun 2017 21:32:48 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <201706302132.v5ULWmg0030245@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Fri, 30 Jun 2017 21:32:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r320510 - in stable/10/bin/sh: . tests/expansion X-SVN-Group: stable-10 X-SVN-Commit-Author: jilles X-SVN-Commit-Paths: in stable/10/bin/sh: . tests/expansion X-SVN-Commit-Revision: 320510 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Jun 2017 21:32:50 -0000 Author: jilles Date: Fri Jun 30 21:32:48 2017 New Revision: 320510 URL: https://svnweb.freebsd.org/changeset/base/320510 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/10/bin/sh/tests/expansion/cmdsubst23.0 - copied unchanged from r315005, head/bin/sh/tests/expansion/cmdsubst23.0 Modified: stable/10/bin/sh/expand.c stable/10/bin/sh/tests/expansion/Makefile Directory Properties: stable/10/ (props changed) Modified: stable/10/bin/sh/expand.c ============================================================================== --- stable/10/bin/sh/expand.c Fri Jun 30 20:27:51 2017 (r320509) +++ stable/10/bin/sh/expand.c Fri Jun 30 21:32:48 2017 (r320510) @@ -740,8 +740,10 @@ again: /* jump here after setting a variable with ${va 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/10/bin/sh/tests/expansion/Makefile ============================================================================== --- stable/10/bin/sh/tests/expansion/Makefile Fri Jun 30 20:27:51 2017 (r320509) +++ stable/10/bin/sh/tests/expansion/Makefile Fri Jun 30 21:32:48 2017 (r320510) @@ -43,6 +43,7 @@ FILES+= cmdsubst19.0 FILES+= cmdsubst20.0 FILES+= cmdsubst21.0 FILES+= cmdsubst22.0 +FILES+= cmdsubst23.0 FILES+= export1.0 FILES+= export2.0 FILES+= export3.0 Copied: stable/10/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/10/bin/sh/tests/expansion/cmdsubst23.0 Fri Jun 30 21:32:48 2017 (r320510, 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 ]