From patchwork Mon May 7 17:14:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 10384535 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 B131460159 for ; Mon, 7 May 2018 17:14:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96800289B5 for ; Mon, 7 May 2018 17:14:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8AF9728A06; Mon, 7 May 2018 17:14:07 +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 37353289B5 for ; Mon, 7 May 2018 17:14:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752312AbeEGROF (ORCPT ); Mon, 7 May 2018 13:14:05 -0400 Received: from orcrist.hmeau.com ([104.223.48.154]:34192 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752282AbeEGROF (ORCPT ); Mon, 7 May 2018 13:14:05 -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 1fFji7-0002bn-UD; Tue, 08 May 2018 01:14:03 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1fFji7-0007gS-Ng; Tue, 08 May 2018 01:14:03 +0800 Date: Tue, 8 May 2018 01:14:03 +0800 From: Herbert Xu To: DASH Mailing List Subject: parser: Save/restore here-documents in command substitution Message-ID: <20180507171403.xrfkhbqmze4p27xo@gondor.apana.org.au> MIME-Version: 1.0 Content-Disposition: inline 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 This patch changes the parsing of here-documents within command substitution, both old style and new style. In particular, the original here-document list is saved upon the beginning of parsing command substitution and restored when exiting. This means that here-documents outside of command substitution can no longer be filled by text within it and vice-versa. Signed-off-by: Herbert Xu diff --git a/src/parser.c b/src/parser.c index 8e40781..1c56c83 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1363,6 +1363,7 @@ parsebackq: { union node *n; char *str; size_t savelen; + struct heredoc *saveheredoclist; int uninitialized_var(saveprompt); str = NULL; @@ -1427,6 +1428,9 @@ done: *nlpp = (struct nodelist *)stalloc(sizeof (struct nodelist)); (*nlpp)->next = NULL; + saveheredoclist = heredoclist; + heredoclist = NULL; + if (oldstyle) { saveprompt = doprompt; doprompt = 0; @@ -1439,17 +1443,18 @@ done: else { if (readtoken() != TRP) synexpect(TRP); + setinputstring(nullstr); + parseheredoc(); } + heredoclist = saveheredoclist; + (*nlpp)->n = n; - if (oldstyle) { - /* - * Start reading from old file again, ignoring any pushed back - * tokens left from the backquote parsing - */ - popfile(); + /* Start reading from old file again. */ + popfile(); + /* Ignore any pushed back tokens left from the backquote parsing. */ + if (oldstyle) tokpushback = 0; - } while (stackblocksize() <= savelen) growstackblock(); STARTSTACKSTR(out);