From 54bef2a8efd21e9992a9d26cf30c5b26cbc0e21a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 19 Feb 2020 15:30:20 +0100 Subject: ash: eval: Fail immediately with redirections errors for simple command Upstream commit: Date: Sat, 19 May 2018 02:39:54 +0800 eval: Fail immediately with redirections errors for simple command 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 Signed-off-by: Denys Vlasenko --- shell/ash.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'shell/ash.c') diff --git a/shell/ash.c b/shell/ash.c index 145896229..5570057e9 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -10253,6 +10253,17 @@ evalcommand(union node *cmd, int flags) } status = redirectsafe(cmd->ncmd.redirect, REDIR_PUSH | REDIR_SAVEFD2); + if (status) { + bail: + exitstatus = status; + + /* We have a redirection error. */ + if (spclbltin > 0) + raise_exception(EXERROR); + + goto out; + } + for (argp = cmd->ncmd.assign; argp; argp = argp->narg.next) { struct strlist **spp; @@ -10304,28 +10315,17 @@ evalcommand(union node *cmd, int flags) ) { find_command(argv[0], &cmdentry, cmd_flag | DO_ERR, path ? path : pathval()); - if (cmdentry.cmdtype == CMDUNKNOWN) { - status = 127; - flush_stdout_stderr(); - goto bail; - } - } - - if (status) { - bail: - exitstatus = status; - - /* We have a redirection error. */ - if (spclbltin > 0) - raise_exception(EXERROR); - - goto out; } jp = NULL; /* Execute the command. */ switch (cmdentry.cmdtype) { + case CMDUNKNOWN: + status = 127; + flush_stdout_stderr(); + goto bail; + default: { #if ENABLE_FEATURE_SH_STANDALONE \ -- cgit v1.2.3