ash: eval: Fail immediately with redirections errors for simple command
authorDenys Vlasenko <vda.linux@googlemail.com>
Wed, 19 Feb 2020 14:30:20 +0000 (15:30 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 20 Feb 2020 08:36:51 +0000 (09:36 +0100)
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 <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/ash.c
shell/ash_test/ash-redir/redir_exec1.right

index 1458962295ee66ddb12c6454645acebaf729757a..5570057e939abd00e0820f88d76b8852b92c1bfa 100644 (file)
@@ -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 \
index c98455bf541b2f11d31218325ab8ee467f87be91..26a664edcc6e8084be646114fea7009c64064cb5 100644 (file)
@@ -1,2 +1 @@
 ./redir_exec1.tests: line 1: can't create /cant/be/created: nonexistent directory
-First