Module Name:    src
Committed By:   martin
Date:           Sat Aug 25 11:45:40 UTC 2018

Modified Files:
        src/bin/sh [netbsd-8]: eval.c

Log Message:
Pull up following revision(s) (requested by kre in ticket #982):

        bin/sh/eval.c: revision 1.157

PR bin/42184 PR bin/52687  (detailing the same bug).

Fix "command not found" handling so that the error message
goes to stderr (after any redirections are applied).

More importantly, in

        foo > /tmp/junk

/tmp/junk should be created, before any attempt is made
to execute (the assumed non-existing) "foo".

All this was always true for any command (not found command)
containing a / in its name

        foo/bar >/tmp/junk  2>>/tmp/errs

would have created /tmp/junk, then complained (in /tmp/errs)
about foo/bar not being found.   Now that happens for ordinary
commands as well.

The fix (which I found when I saw differences between our
code and FreeBSD's, where, for the benefit of PR 42184,
this has been fixed, sometime in the past 9 years) is
frighteningly simple.   Simply do not short circuit execution
(or print any error) when the initial lookup fails to
find the command - it will fail anyway when we actually
try running it.   The cost is a (seemingly unnecessary,
except that it really is) fork in this case.

This is what I had been planning, but I expected it would
be much more difficult than it turned out....

XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.140.2.3 -r1.140.2.4 src/bin/sh/eval.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/sh/eval.c
diff -u src/bin/sh/eval.c:1.140.2.3 src/bin/sh/eval.c:1.140.2.4
--- src/bin/sh/eval.c:1.140.2.3	Fri Jul 13 14:29:15 2018
+++ src/bin/sh/eval.c	Sat Aug 25 11:45:40 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: eval.c,v 1.140.2.3 2018/07/13 14:29:15 martin Exp $	*/
+/*	$NetBSD: eval.c,v 1.140.2.4 2018/08/25 11:45:40 martin Exp $	*/
 
 /*-
  * Copyright (c) 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)eval.c	8.9 (Berkeley) 6/8/95";
 #else
-__RCSID("$NetBSD: eval.c,v 1.140.2.3 2018/07/13 14:29:15 martin Exp $");
+__RCSID("$NetBSD: eval.c,v 1.140.2.4 2018/08/25 11:45:40 martin Exp $");
 #endif
 #endif /* not lint */
 
@@ -903,7 +903,7 @@ evalcommand(union node *cmd, int flgs, s
 		cmdentry.u.bltin = bltincmd;
 	} else {
 		static const char PATH[] = "PATH=";
-		int cmd_flags = DO_ERR;
+		int cmd_flags = 0;
 
 		/*
 		 * Modify the command lookup path, if a PATH= assignment
@@ -917,11 +917,20 @@ evalcommand(union node *cmd, int flgs, s
 			int argsused, use_syspath;
 
 			find_command(argv[0], &cmdentry, cmd_flags, path);
+#if 0
+			/*
+			 * This short circuits all of the processing that
+			 * should be done (including processing the
+			 * redirects), so just don't ...
+			 *
+			 * (eventually this whole #if'd block will vanish)
+			 */
 			if (cmdentry.cmdtype == CMDUNKNOWN) {
 				exitstatus = 127;
 				flushout(&errout);
 				goto out;
 			}
+#endif
 
 			/* implement the 'command' builtin here */
 			if (cmdentry.cmdtype != CMDBUILTIN ||
@@ -947,9 +956,10 @@ evalcommand(union node *cmd, int flgs, s
 
 	/* Fork off a child process if necessary. */
 	if (cmd->ncmd.backgnd || (trap[0] && (flags & EV_EXIT) != 0)
-	 || (cmdentry.cmdtype == CMDNORMAL && (flags & EV_EXIT) == 0)
-	 || ((flags & EV_BACKCMD) != 0
-	    && ((cmdentry.cmdtype != CMDBUILTIN && cmdentry.cmdtype != CMDSPLBLTIN)
+	 || ((cmdentry.cmdtype == CMDNORMAL || cmdentry.cmdtype == CMDUNKNOWN)
+	     && (flags & EV_EXIT) == 0)
+	 || ((flags & EV_BACKCMD) != 0 &&
+	    ((cmdentry.cmdtype != CMDBUILTIN && cmdentry.cmdtype != CMDSPLBLTIN)
 		 || cmdentry.u.bltin == dotcmd
 		 || cmdentry.u.bltin == evalcmd))) {
 		INTOFF;

Reply via email to