Module Name:    src
Committed By:   kre
Date:           Mon Jan 21 14:24:44 UTC 2019

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

Log Message:
Fix an amazing crazy botch (of mine) when expanding prompt strings
(PS1 etc) which, if the shell were already exiting, and a prompt
were to be expanded (which only really happens if -x is enabled,
and an exit trap is set, so the commands in the trap need PS4
expanded and written, last thing, before the shell exits) the shell
would instead simply exit when it finished expanding PS4 (before
even writing it, or the xtrace output).

There were more conditions required to set up the environment for
this to actually occur (it seems to only happen when the exit trap
is set in a function, called in a command substitution) but that's
unimportant, the code was nonsense.

Problem noticed by Martijn Dekker.

XXX pullup -8


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 src/bin/sh/parser.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/parser.c
diff -u src/bin/sh/parser.c:1.161 src/bin/sh/parser.c:1.162
--- src/bin/sh/parser.c:1.161	Tue Jan 15 14:17:49 2019
+++ src/bin/sh/parser.c	Mon Jan 21 14:24:44 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: parser.c,v 1.161 2019/01/15 14:17:49 kre Exp $	*/
+/*	$NetBSD: parser.c,v 1.162 2019/01/21 14:24:44 kre Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)parser.c	8.7 (Berkeley) 5/16/95";
 #else
-__RCSID("$NetBSD: parser.c,v 1.161 2019/01/15 14:17:49 kre Exp $");
+__RCSID("$NetBSD: parser.c,v 1.162 2019/01/21 14:24:44 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -2484,23 +2484,26 @@ expandonstack(char *ps, int cmdsub, int 
 			expandarg(&n, NULL, 0);
 			result = stackblock();
 		}
-		INTOFF;
+	} else {
+		psp.v_current_parser = saveparser;
+		xflag = save_x;
+		popfilesupto(savetopfile);
+		handler = savehandler;
+
+		if (exception == EXEXIT)
+			longjmp(handler->loc, 1);
+		if (exception == EXINT)
+			exraise(SIGINT);
+		return ps;
 	}
 	psp.v_current_parser = saveparser;
 	xflag = save_x;
 	popfilesupto(savetopfile);
 	handler = savehandler;
 
-	if (exception == EXEXIT)
-		longjmp(handler->loc, 1);
 
-	if (result != NULL) {
-		INTON;
-	} else {
-		if (exception == EXINT)
-			exraise(SIGINT);
+	if (result == NULL)
 		result = ps;
-	}
 
 	return result;
 }

Reply via email to