From patchwork Mon Mar 26 16:39:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 10308273 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 3F34F600CC for ; Mon, 26 Mar 2018 16:39:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E3262976F for ; Mon, 26 Mar 2018 16:39:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 204792979C; Mon, 26 Mar 2018 16:39:43 +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 08A6C2976F for ; Mon, 26 Mar 2018 16:39:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751249AbeCZQjl (ORCPT ); Mon, 26 Mar 2018 12:39:41 -0400 Received: from orcrist.hmeau.com ([104.223.48.154]:35136 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751099AbeCZQjl (ORCPT ); Mon, 26 Mar 2018 12:39:41 -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 1f0V9k-0000bZ-Gu; Tue, 27 Mar 2018 00:39:36 +0800 Received: from herbert by gondobar with local (Exim 4.84_2) (envelope-from ) id 1f0V9j-0002cG-5x; Tue, 27 Mar 2018 00:39:35 +0800 Date: Tue, 27 Mar 2018 00:39:35 +0800 From: Herbert Xu To: DASH Mailing List Subject: eval: Restore input files in evalcommand Message-ID: <20180326163935.GA10015@gondor.apana.org.au> MIME-Version: 1.0 Content-Disposition: inline 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 When evalcommand invokes a command that modifies parsefile and then bails out without popping the file, we need to ensure the input file is restored so that the shell can continue to execute. Reported-by: Martijn Dekker Signed-off-by: Herbert Xu diff --git a/src/eval.c b/src/eval.c index 7498f9d..e5749ef 100644 --- a/src/eval.c +++ b/src/eval.c @@ -694,6 +694,7 @@ evalcommand(union node *cmd, int flags) #endif { struct localvar_list *localvar_stop; + struct parsefile *file_stop; struct redirtab *redir_stop; struct stackmark smark; union node *argp; @@ -722,6 +723,7 @@ evalcommand(union node *cmd, int flags) TRACE(("evalcommand(0x%lx, %d) called\n", (long)cmd, flags)); setstackmark(&smark); localvar_stop = pushlocalvars(); + file_stop = parsefile; back_exitstatus = 0; cmdentry.cmdtype = CMDBUILTIN; @@ -895,6 +897,7 @@ out: if (cmd->ncmd.redirect) popredir(execcmd); unwindredir(redir_stop); + unwindfiles(file_stop); unwindlocalvars(localvar_stop); if (lastarg) /* dsl: I think this is intended to be used to support diff --git a/src/input.c b/src/input.c index e53423c..ae0c4c8 100644 --- a/src/input.c +++ b/src/input.c @@ -479,6 +479,13 @@ popfile(void) } +void unwindfiles(struct parsefile *stop) +{ + while (parsefile != stop) + popfile(); +} + + /* * Return to top level. */ @@ -486,8 +493,7 @@ popfile(void) void popallfiles(void) { - while (parsefile != &basepf) - popfile(); + unwindfiles(&basepf); } diff --git a/src/input.h b/src/input.h index ec97c1d..a9c0517 100644 --- a/src/input.h +++ b/src/input.h @@ -97,5 +97,6 @@ void popstring(void); int setinputfile(const char *, int); void setinputstring(char *); void popfile(void); +void unwindfiles(struct parsefile *); void popallfiles(void); void closescript(void);