Module Name:    src
Committed By:   kre
Date:           Mon Jun 19 03:21:31 UTC 2017

Modified Files:
        src/bin/sh: eval.c

Log Message:
Another fix from FreeBSD (this one from April 2009).

When processing a string (as in eval, trap, or sh -c) don't allow
trailing \n's to destroy the exit status of the last command executed.

That is:
        sh -c 'false

        '
        echo $?
should produce 1, not 0.


To generate a diff of this commit:
cvs rdiff -u -r1.149 -r1.150 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.149 src/bin/sh/eval.c:1.150
--- src/bin/sh/eval.c:1.149	Mon Jun 19 02:51:51 2017
+++ src/bin/sh/eval.c	Mon Jun 19 03:21:31 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: eval.c,v 1.149 2017/06/19 02:51:51 kre Exp $	*/
+/*	$NetBSD: eval.c,v 1.150 2017/06/19 03:21:31 kre 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.149 2017/06/19 02:51:51 kre Exp $");
+__RCSID("$NetBSD: eval.c,v 1.150 2017/06/19 03:21:31 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -220,7 +220,7 @@ evalstring(char *s, int flag)
 
 	while ((n = parsecmd(0)) != NEOF) {
 		XTRACE(DBG_EVAL, ("evalstring: "), showtree(n));
-		if (nflag == 0)
+		if (n && nflag == 0)
 			evaltree(n, flag | EV_MORE);
 		popstackmark(&smark);
 	}

Reply via email to