From patchwork Mon Nov 19 10:43:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 10688473 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-2.web.codeaurora.org (Postfix) with ESMTP id 716EE14D6 for ; Mon, 19 Nov 2018 10:44:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6034729A41 for ; Mon, 19 Nov 2018 10:44:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5383329A4F; Mon, 19 Nov 2018 10:44:01 +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 C5FCC29A41 for ; Mon, 19 Nov 2018 10:44:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727881AbeKSVHO (ORCPT ); Mon, 19 Nov 2018 16:07:14 -0500 Received: from orcrist.hmeau.com ([104.223.48.154]:43492 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727545AbeKSVHO (ORCPT ); Mon, 19 Nov 2018 16:07:14 -0500 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 1gOh26-0008PH-Qm; Mon, 19 Nov 2018 18:43:58 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1gOh26-0001N3-1H; Mon, 19 Nov 2018 18:43:58 +0800 Date: Mon, 19 Nov 2018 18:43:58 +0800 From: Herbert Xu To: Ron Yorston Cc: dash@vger.kernel.org, contact@emersion.fr Subject: parser: Do not push token back before parseheredoc Message-ID: <20181119104357.hll2lcq4bfaqabpo@gondor.apana.org.au> References: <5b754dc5.1MDIHBTGP2xy8gXF%rmy@frippery.org> <20180817130835.564r4b727ybj4nep@gondor.apana.org.au> <20181119103059.ginrpfyresojc2vr@gondor.apana.org.au> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20181119103059.ginrpfyresojc2vr@gondor.apana.org.au> 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 Sorry for the repost, I'm trying to get this into patchwork. ---8<--- When we read the first token in list() we use peektoken instead of readtoken as the following code needs to use the same token again. However, this is wrong when we're in a here-document as it will clobber the saved token without resetting the tokpushback flag. This patch fixes it by doing the tokpushback after parseheredoc and setting lasttoken again if parseheredoc was called. Reported-by: Ron Yorston Fixes: 7c245aa8ed33 ("[PARSER] Simplify EOF/newline handling in...") Fixes: ee5cbe9fd6bc ("[SHELL] Optimize dash -c "command" to avoid a fork") Signed-off-by: Herbert Xu Tested-by: Simon Ser diff --git a/src/parser.c b/src/parser.c index c4e6378..1f9e8ec 100644 --- a/src/parser.c +++ b/src/parser.c @@ -166,7 +166,7 @@ list(int nlflag) n1 = NULL; for (;;) { - switch (peektoken()) { + switch (readtoken()) { case TNL: if (!(nlflag & 1)) break; @@ -177,9 +177,12 @@ list(int nlflag) if (!n1 && (nlflag & 1)) n1 = NEOF; parseheredoc(); + tokpushback++; + lasttoken = TEOF; return n1; } + tokpushback++; checkkwd = CHKNL | CHKKWD | CHKALIAS; if (nlflag == 2 && tokendlist[peektoken()]) return n1;