From patchwork Fri May 11 15:41:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 10394625 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 A5F2360153 for ; Fri, 11 May 2018 15:41:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCCDD28F28 for ; Fri, 11 May 2018 15:41:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B13FC28EB7; Fri, 11 May 2018 15:41:35 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, 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 1EB0928EB7 for ; Fri, 11 May 2018 15:41:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751293AbeEKPlc (ORCPT ); Fri, 11 May 2018 11:41:32 -0400 Received: from orcrist.hmeau.com ([104.223.48.154]:44584 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751130AbeEKPla (ORCPT ); Fri, 11 May 2018 11:41:30 -0400 Received: from gondobar.mordor.me.apana.org.au ([192.168.128.4] helo=gondobar) by deadmen.hmeau.com with esmtps (Exim 4.89 #2 (Debian)) id 1fHAAh-0005q7-S1; Fri, 11 May 2018 23:41:27 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1fHAAf-00066r-JG; Fri, 11 May 2018 23:41:25 +0800 Date: Fri, 11 May 2018 23:41:25 +0800 From: Herbert Xu To: Leah Neukirchen Cc: dash@vger.kernel.org Subject: Re: Regression in dash 0.5.10 related to string parsing Message-ID: <20180511154125.rncgrafcqlmt3gye@gondor.apana.org.au> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <87in7u4j7i.fsf@gmail.com> X-Newsgroups: apana.lists.os.linux.dash Organization: Core User-Agent: NeoMutt/20170113 (1.7.2) Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Leah Neukirchen wrote: > Hi, > > Commit ab1cecb40, first released in 0.5.10, introduces a parsing bug > related to backslashes in singly-quoted strings: > > echo 'foo\ > bar' > > According to POSIX, this has to output > > foo\ > bar > > However, in dash 0.5.10, it outputs "foobar". > > Found by users of the Void Linux project: > https://github.com/voidlinux/void-packages/issues/14282 Thanks for the report. This patch should fix the problem: ---8<--- Subject: parser: Fix incorrect eating of backslash newlines With the introduction of synstack->syntax, a number of references to the syntax variable was missed during the conversion. This causes backslash newlines to be incorrectly removed in single quote context. This patch also combines these calls into a new helper function pgetc_top. Fixes: ab1cecb40478 ("parser: Add syntax stack for recursive...") Reported-by: Leah Neukirchen Signed-off-by: Herbert Xu diff --git a/src/parser.c b/src/parser.c index 8e40781..8bd3db4 100644 --- a/src/parser.c +++ b/src/parser.c @@ -853,6 +853,11 @@ static int pgetc_eatbnl(void) return c; } +static int pgetc_top(struct synstack *stack) +{ + return stack->syntax == SQSYNTAX ? pgetc() : pgetc_eatbnl(); +} + static void synstack_push(struct synstack **stack, struct synstack *next, const char *syntax) { @@ -915,7 +920,7 @@ readtoken1(int firstc, char const *syntax, char *eofmark, int striptabs) attyline(); if (synstack->syntax == BASESYNTAX) return readtoken(); - c = syntax == SQSYNTAX ? pgetc() : pgetc_eatbnl(); + c = pgetc_top(synstack); goto loop; } #endif @@ -929,7 +934,7 @@ readtoken1(int firstc, char const *syntax, char *eofmark, int striptabs) goto endword; /* exit outer loop */ USTPUTC(c, out); nlprompt(); - c = syntax == SQSYNTAX ? pgetc() : pgetc_eatbnl(); + c = pgetc_top(synstack); goto loop; /* continue outer loop */ case CWORD: USTPUTC(c, out); @@ -1056,7 +1061,7 @@ toggledq: USTPUTC(c, out); } } - c = syntax == SQSYNTAX ? pgetc() : pgetc_eatbnl(); + c = pgetc_top(synstack); } } endword: