From patchwork Mon Apr 2 17:04:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 10320077 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6843760247 for ; Mon, 2 Apr 2018 17:05:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DBD028986 for ; Mon, 2 Apr 2018 17:05:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A90628A03; Mon, 2 Apr 2018 17:05:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 579C628986 for ; Mon, 2 Apr 2018 17:05:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752938AbeDBRFR (ORCPT ); Mon, 2 Apr 2018 13:05:17 -0400 Received: from orcrist.hmeau.com ([104.223.48.154]:56756 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752531AbeDBRFR (ORCPT ); Mon, 2 Apr 2018 13:05:17 -0400 Received: from gondobar.mordor.me.apana.org.au ([192.168.128.4] helo=gondobar) by deadmen.hmeau.com with esmtp (Exim 4.84_2 #2 (Debian)) id 1f32tA-0004aQ-9R; Tue, 03 Apr 2018 01:05:00 +0800 Received: from herbert by gondobar with local (Exim 4.84_2) (envelope-from ) id 1f32t5-0000Cj-7Y; Tue, 03 Apr 2018 01:04:55 +0800 Date: Tue, 3 Apr 2018 01:04:55 +0800 From: Herbert Xu To: Denys Vlasenko Cc: Harald van Dijk , Martijn Dekker , dash@vger.kernel.org Subject: Re: dash bug: double-quoted "\" breaks glob protection for next char Message-ID: <20180402170455.GA750@gondor.apana.org.au> References: <7dac7df9-4093-095e-dd71-2d7383edd8c3@inlv.org> <041881f9-9084-4083-345a-8f85792b48ef@gigawatt.nl> <20180307162944.GA4960@gondor.apana.org.au> <066e53c4-ad05-35bb-2da2-a377ce8f4629@gigawatt.nl> <2192f69d-29ec-461c-d09e-cb63e309e8de@gigawatt.nl> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon, Apr 02, 2018 at 02:13:03PM +0200, Denys Vlasenko wrote: > > I was trying some of the beautiful atrocities from one of earlier > Harald's emails and this one fails in current dash git: > > # x="''''"; echo "${x#"${x+''}"''}" > dash: 12: Syntax error: Missing '}' Thanks for the report. This patch should fix it. ---8<--- Subject: parser: Fix parameter expansion inside inner double quotes The parsing of parameter expansion inside inner double quotes breaks because we never look for ENDVAR while innerdq is true. echo "${x#"${x+''}"''} This patch fixes it by pushing the syntax stack if innerdq is true and we enter a new parameter expansion. This patch also fixes a corner case where a bad substitution error occurs within arithmetic expansion. Reported-by: Denys Vlasenko Fixes: ab1cecb40478 (" parser: Add syntax stack for recursive...") Signed-off-by: Herbert Xu diff --git a/src/parser.c b/src/parser.c index 6a8a4a4..a856458 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1324,10 +1324,11 @@ badsub: pungetc(); } - if (newsyn == ARISYNTAX && subtype > VSNORMAL) + if (newsyn == ARISYNTAX) newsyn = DQSYNTAX; - if (newsyn != synstack->syntax) { + if ((newsyn != synstack->syntax || synstack->innerdq) && + subtype != VSNORMAL) { synstack_push(&synstack, synstack->prev ?: alloca(sizeof(*synstack)),