From patchwork Fri May 18 18:39:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herbert Xu X-Patchwork-Id: 10411859 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 D171660383 for ; Fri, 18 May 2018 18:39:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C139C28A8E for ; Fri, 18 May 2018 18:39:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B620F28A8F; Fri, 18 May 2018 18:39:56 +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 5E19228A91 for ; Fri, 18 May 2018 18:39:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751744AbeERSj4 (ORCPT ); Fri, 18 May 2018 14:39:56 -0400 Received: from orcrist.hmeau.com ([104.223.48.154]:48260 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751664AbeERSjz (ORCPT ); Fri, 18 May 2018 14:39:55 -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 1fJkIE-0006F3-Hf for ; Sat, 19 May 2018 02:39:54 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1fJkIE-0005px-1D; Sat, 19 May 2018 02:39:54 +0800 Subject: [v3 PATCH 15/17] eval: Fail immediately with redirections errors for simple command References: <20180518183844.zizl3xevlcm4gzsj@gondor.apana.org.au> To: DASH Mailing List Message-Id: From: Herbert Xu Date: Sat, 19 May 2018 02:39:54 +0800 Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Previously, dash would continue to perform variable expansions even if a redirection error occured. This patch changes it so that it fails immediately. Signed-off-by: Herbert Xu --- src/eval.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/src/eval.c b/src/eval.c index 22fe2d7..122613b 100644 --- a/src/eval.c +++ b/src/eval.c @@ -818,6 +818,17 @@ evalcommand(union node *cmd, int flags) redir_stop = pushredir(cmd->ncmd.redirect); status = redirectsafe(cmd->ncmd.redirect, REDIR_PUSH|REDIR_SAVEFD2); + if (status) { +bail: + exitstatus = status; + + /* We have a redirection error. */ + if (spclbltin > 0) + exraise(EXERROR); + + goto out; + } + for (argp = cmd->ncmd.assign; argp; argp = argp->narg.next) { struct strlist **spp; @@ -848,30 +859,19 @@ evalcommand(union node *cmd, int flags) !(cmdentry.u.cmd->flags & BUILTIN_REGULAR)) { find_command(argv[0], &cmdentry, cmd_flag | DO_ERR, unlikely(path) ? path : pathval()); - if (cmdentry.cmdtype == CMDUNKNOWN) { - status = 127; -#ifdef FLUSHERR - flushout(&errout); -#endif - goto bail; - } - } - - if (status) { -bail: - exitstatus = status; - - /* We have a redirection error. */ - if (spclbltin > 0) - exraise(EXERROR); - - goto out; } jp = NULL; /* Execute the command. */ switch (cmdentry.cmdtype) { + case CMDUNKNOWN: + status = 127; +#ifdef FLUSHERR + flushout(&errout); +#endif + goto bail; + default: /* Fork off a child process if necessary. */ if (!(flags & EV_EXIT) || have_traps()) {