From patchwork Fri Mar 9 15:07:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 10270885 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 E443D603B5 for ; Fri, 9 Mar 2018 15:08:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5BCA29E4D for ; Fri, 9 Mar 2018 15:08:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA1B429E52; Fri, 9 Mar 2018 15:08:13 +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 4BA3F29E4D for ; Fri, 9 Mar 2018 15:08:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751169AbeCIPIM (ORCPT ); Fri, 9 Mar 2018 10:08:12 -0500 Received: from orcrist.hmeau.com ([104.223.48.154]:60518 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751102AbeCIPIM (ORCPT ); Fri, 9 Mar 2018 10:08:12 -0500 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 1euJcj-000248-LY; Fri, 09 Mar 2018 23:07:57 +0800 Received: from herbert by gondobar with local (Exim 4.84_2) (envelope-from ) id 1euJcg-0003W1-0A; Fri, 09 Mar 2018 23:07:54 +0800 Date: Fri, 9 Mar 2018 23:07:53 +0800 From: Herbert Xu To: Harald van Dijk Cc: Martijn Dekker , Denys Vlasenko , dash@vger.kernel.org Subject: [PATCH] parser: Fix single-quoted patterns in here-documents Message-ID: <20180309150753.GC13375@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> <20180308075549.GB8211@gondor.apana.org.au> <160da770-3475-2b8f-2f33-817bc1948219@gigawatt.nl> <20180308161402.GA9757@gondor.apana.org.au> <4286cde4-73fd-d18d-0b5d-cdad9da3279e@gigawatt.nl> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4286cde4-73fd-d18d-0b5d-cdad9da3279e@gigawatt.nl> 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 Thu, Mar 08, 2018 at 07:35:53PM +0100, Harald van Dijk wrote: > > Related: > > x=*; cat < ${x#'*'} > EOF > > This shouldn't print anything either: because the * is quoted, it should be > taken as a literal and removed from $x. > > Re-testing, I see this didn't work properly with my patch either. I don't think this is related to our patches at all. It's an independent bug. The fix isn't too hard. ---8<--- The script x=* cat <<- EOF ${x#'*'} EOF prints * instead of nothing as it should. The problem is that when we're in sqsyntax context in a here-document, we won't add CTLESC as we should. This patch fixes it: Reported-by: Harald van Dijk Signed-off-by: Herbert Xu diff --git a/src/parser.c b/src/parser.c index 3aeb9f6..d86d71e 100644 --- a/src/parser.c +++ b/src/parser.c @@ -940,7 +940,8 @@ readtoken1(int firstc, char const *syntax, char *eofmark, int striptabs) USTPUTC(c, out); break; case CCTL: - if (eofmark == NULL || synstack->dblquote) + if ((!eofmark) | synstack->dblquote | + synstack->varnest) USTPUTC(CTLESC, out); USTPUTC(c, out); break;