From owner-svn-src-head@FreeBSD.ORG Thu Dec 16 23:28:20 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D99D0106566B; Thu, 16 Dec 2010 23:28:20 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id C7EC38FC14; Thu, 16 Dec 2010 23:28:20 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id oBGNSKAp005701; Thu, 16 Dec 2010 23:28:20 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id oBGNSKPE005698; Thu, 16 Dec 2010 23:28:20 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201012162328.oBGNSKPE005698@svn.freebsd.org> From: Jilles Tjoelker Date: Thu, 16 Dec 2010 23:28:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r216496 - in head: bin/sh tools/regression/bin/sh/expansion X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Dec 2010 23:28:20 -0000 Author: jilles Date: Thu Dec 16 23:28:20 2010 New Revision: 216496 URL: http://svn.freebsd.org/changeset/base/216496 Log: sh: Fix corruption of command substitutions with special chars after newline The CTLESC byte to protect a special character was output before instead of after a newline directly preceding the special character. The special handling of newlines is because command substitutions discard all trailing newlines. Added: head/tools/regression/bin/sh/expansion/cmdsubst3.0 (contents, props changed) Modified: head/bin/sh/expand.c Modified: head/bin/sh/expand.c ============================================================================== --- head/bin/sh/expand.c Thu Dec 16 21:01:02 2010 (r216495) +++ head/bin/sh/expand.c Thu Dec 16 23:28:20 2010 (r216496) @@ -499,8 +499,6 @@ expbackq(union node *cmd, int quoted, in } lastc = *p++; if (lastc != '\0') { - if (quotes && syntax[(int)lastc] == CCTL) - STPUTC(CTLESC, dest); if (lastc == '\n') { nnl++; } else { @@ -508,6 +506,8 @@ expbackq(union node *cmd, int quoted, in nnl--; STPUTC('\n', dest); } + if (quotes && syntax[(int)lastc] == CCTL) + STPUTC(CTLESC, dest); STPUTC(lastc, dest); } } Added: head/tools/regression/bin/sh/expansion/cmdsubst3.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/regression/bin/sh/expansion/cmdsubst3.0 Thu Dec 16 23:28:20 2010 (r216496) @@ -0,0 +1,20 @@ +# $FreeBSD$ + +e= +for i in 0 1 2 3; do + for j in 0 1 2 3 4 5 6 7; do + for k in 0 1 2 3 4 5 6 7; do + case $i$j$k in + 000) continue ;; + esac + e="$e\n\\$i$j$k" + done + done +done +e1=$(printf "$e") +e2="$(printf "$e")" +[ "${#e1}" = 510 ] || echo length bad +[ "$e1" = "$e2" ] || echo e1 != e2 +[ "$e1" = "$(printf "$e")" ] || echo quoted bad +IFS= +[ "$e1" = $(printf "$e") ] || echo unquoted bad