When an error occurs in a builtin from which we do not exit

(a normal builtin, though those are not genrally an issue for
this problem, or a special builtin that has been prefixed by "command")
make sure that we discard any pending input that might have been
queued up, but not yet processed.

We had the mechanism to fix this from when expansion of PS1 etc
was added (which has a similar problem to deal with) - all taken
from FreeBSD - but did not bother to use it here until now...

This fixes an error detected by newly added ATF tests of the eval
builtin, where
	eval 'syntax error
		another command'
would go ahead and evaluate "another command" which should not
happen (note: only when there was a \n between the two).
This commit is contained in:
kre 2019-01-09 10:57:43 +00:00
parent aa6bc89002
commit a582e232a9
1 changed files with 8 additions and 4 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: eval.c,v 1.168 2018/12/03 06:43:19 kre Exp $ */
/* $NetBSD: eval.c,v 1.169 2019/01/09 10:57:43 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.168 2018/12/03 06:43:19 kre Exp $");
__RCSID("$NetBSD: eval.c,v 1.169 2019/01/09 10:57:43 kre Exp $");
#endif
#endif /* not lint */
@ -871,6 +871,7 @@ evalcommand(union node *cmd, int flgs, struct backcmd *backcmd)
const char *volatile savecmdname;
volatile struct shparam saveparam;
struct localvar *volatile savelocalvars;
struct parsefile *volatile savetopfile;
volatile int e;
char * volatile lastarg;
const char * volatile path = pathval();
@ -1237,11 +1238,13 @@ evalcommand(union node *cmd, int flgs, struct backcmd *backcmd)
mode |= REDIR_BACKQ;
}
e = -1;
savehandler = handler;
savecmdname = commandname;
handler = &jmploc;
savetopfile = getcurrentfile();
savehandler = handler;
temp_path = 0;
if (!setjmp(jmploc.loc)) {
handler = &jmploc;
/*
* We need to ensure the command hash table isn't
* corrupted by temporary PATH assignments.
@ -1307,6 +1310,7 @@ evalcommand(union node *cmd, int flgs, struct backcmd *backcmd)
if ((e != EXERROR && e != EXEXEC)
|| cmdentry.cmdtype == CMDSPLBLTIN)
exraise(e);
popfilesupto(savetopfile);
FORCEINTON;
}
if (cmdentry.u.bltin != execcmd)