[klibc] [klibc:update-dash] dash: eval: Fail immediately with redirections errors for simple command

klibc-bot for Herbert Xu herbert at gondor.apana.org.au
Sat Mar 28 14:49:24 PDT 2020


Commit-ID:  e9dcd440e4ba1812181839ba803dc0fe2909c43e
Gitweb:     http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=e9dcd440e4ba1812181839ba803dc0fe2909c43e
Author:     Herbert Xu <herbert at gondor.apana.org.au>
AuthorDate: Sat, 19 May 2018 02:39:54 +0800
Committer:  Ben Hutchings <ben at decadent.org.uk>
CommitDate: Sat, 28 Mar 2020 21:42:55 +0000

[klibc] dash: eval: Fail immediately with redirections errors for simple command

[ dash commit 8ca5c96f0c45a4e224193820cb2aaf10059bfb07 ]

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 at gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben at decadent.org.uk>

---
 usr/dash/eval.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/usr/dash/eval.c b/usr/dash/eval.c
index 9e88fef2..fc5a594a 100644
--- a/usr/dash/eval.c
+++ b/usr/dash/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()) {


More information about the klibc mailing list