Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh When an error occurs in a builtin from which we do no...



details:   https://anonhg.NetBSD.org/src/rev/975d7020d2b0
branches:  trunk
changeset: 838280:975d7020d2b0
user:      kre <kre%NetBSD.org@localhost>
date:      Wed Jan 09 10:57:43 2019 +0000

description:
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).

diffstat:

 bin/sh/eval.c |  12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diffs (50 lines):

diff -r 37e01103a419 -r 975d7020d2b0 bin/sh/eval.c
--- a/bin/sh/eval.c     Wed Jan 09 10:51:23 2019 +0000
+++ b/bin/sh/eval.c     Wed Jan 09 10:57:43 2019 +0000
@@ -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 @@
        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 @@
                        mode |= REDIR_BACKQ;
                }
                e = -1;
+               savecmdname = commandname;
+               savetopfile = getcurrentfile();
                savehandler = handler;
-               savecmdname = commandname;
-               handler = &jmploc;
                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 @@
                        if ((e != EXERROR && e != EXEXEC)
                            || cmdentry.cmdtype == CMDSPLBLTIN)
                                exraise(e);
+                       popfilesupto(savetopfile);
                        FORCEINTON;
                }
                if (cmdentry.u.bltin != execcmd)



Home | Main Index | Thread Index | Old Index