PR bin/48875

Revert the changes that were made 19 May 2016 (principally eval.c 1.125)
and the bug fixes in subsequent days (eval.c 1.126 and 1.127) and also
update some newer code that was added more recently which acted in
accordance with those changes (make that code be as it would have been
if the changes now being reverted had never been made).

While the changes made did solve the problem, in a sense, they were
never correct (see the PR for some discussion) and it had always been
intended that they be reverted.   However, in practical sh code, no
issues were reported - until just recently - so nothing was done,
until now...

After this commit, the validate_fn_redirects test case of the sh ATF
test t_redir will fail.   In particular, the subtest of that test
case which is described in the source (of the test) as:
	This one is the real test for PR bin/48875
will fail.

Alternative changes, not to "fix" the problem in the PR, but to
often avoid it will be coming very soon - after which that ATF
test will succeed again.

XXX pullup-8
This commit is contained in:
kre 2018-08-19 11:16:13 +00:00
parent 3a41fe18d0
commit 120267c338
3 changed files with 21 additions and 32 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: eval.c,v 1.157 2018/08/14 13:36:42 kre Exp $ */
/* $NetBSD: eval.c,v 1.158 2018/08/19 11:16:13 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.157 2018/08/14 13:36:42 kre Exp $");
__RCSID("$NetBSD: eval.c,v 1.158 2018/08/19 11:16:13 kre Exp $");
#endif
#endif /* not lint */
@ -221,7 +221,7 @@ evalstring(char *s, int flag)
while ((n = parsecmd(0)) != NEOF) {
XTRACE(DBG_EVAL, ("evalstring: "), showtree(n));
if (n && nflag == 0)
evaltree(n, flag | EV_MORE);
evaltree(n, flag);
popstackmark(&smark);
}
popfile();
@ -256,20 +256,19 @@ evaltree(union node *n, int flags)
getpid(), n, NODETYPENAME(n->type), n->type, flags));
switch (n->type) {
case NSEMI:
evaltree(n->nbinary.ch1, (sflags & EV_TESTED) |
(n->nbinary.ch2 ? EV_MORE : 0));
evaltree(n->nbinary.ch1, flags & EV_TESTED);
if (nflag || evalskip)
goto out;
evaltree(n->nbinary.ch2, flags);
break;
case NAND:
evaltree(n->nbinary.ch1, EV_TESTED | EV_MORE);
evaltree(n->nbinary.ch1, EV_TESTED);
if (nflag || evalskip || exitstatus != 0)
goto out;
evaltree(n->nbinary.ch2, flags);
break;
case NOR:
evaltree(n->nbinary.ch1, EV_TESTED | EV_MORE);
evaltree(n->nbinary.ch1, EV_TESTED);
if (nflag || evalskip || exitstatus == 0)
goto out;
evaltree(n->nbinary.ch2, flags);
@ -296,14 +295,14 @@ evaltree(union node *n, int flags)
}
break;
case NSUBSHELL:
evalsubshell(n, flags & ~EV_MORE);
evalsubshell(n, flags);
do_etest = !(flags & EV_TESTED);
break;
case NBACKGND:
evalsubshell(n, flags & ~EV_MORE);
evalsubshell(n, flags);
break;
case NIF: {
evaltree(n->nif.test, EV_TESTED | EV_MORE);
evaltree(n->nif.test, EV_TESTED);
if (nflag || evalskip)
goto out;
if (exitstatus == 0)
@ -331,11 +330,11 @@ evaltree(union node *n, int flags)
exitstatus = 0;
break;
case NNOT:
evaltree(n->nnot.com, (sflags & EV_MORE) | EV_TESTED);
evaltree(n->nnot.com, EV_TESTED);
exitstatus = !exitstatus;
break;
case NDNOT:
evaltree(n->nnot.com, (sflags & EV_MORE) | EV_TESTED);
evaltree(n->nnot.com, EV_TESTED);
if (exitstatus != 0)
exitstatus = 1;
break;
@ -379,7 +378,7 @@ evalloop(union node *n, int flags)
CTRACE(DBG_EVAL, ("\n"));
for (;;) {
evaltree(n->nbinary.ch1, EV_TESTED | EV_MORE);
evaltree(n->nbinary.ch1, EV_TESTED);
if (nflag)
break;
if (evalskip) {
@ -398,7 +397,7 @@ evalloop(union node *n, int flags)
if (exitstatus == 0)
break;
}
evaltree(n->nbinary.ch2, (flags & EV_TESTED) | EV_MORE);
evaltree(n->nbinary.ch2, flags & EV_TESTED);
status = exitstatus;
if (evalskip)
goto skipping;
@ -431,11 +430,6 @@ evalfor(union node *n, int flags)
loopnest++;
for (sp = arglist.list ; sp ; sp = sp->next) {
int f = flags & (EV_TESTED | EV_MORE);
if (sp->next)
f |= EV_MORE;
if (xflag) {
outxstr(expandstr(ps4val(), line_number));
outxstr("for ");
@ -447,7 +441,7 @@ evalfor(union node *n, int flags)
}
setvar(n->nfor.var, sp->text, 0);
evaltree(n->nfor.body, f);
evaltree(n->nfor.body, flags & EV_TESTED);
status = exitstatus;
if (nflag)
break;
@ -493,8 +487,7 @@ evalcase(union node *n, int flags)
else
ncp = NULL;
line_number = cp->nclist.lineno;
evaltree(cp->nclist.body,
ncp ? (flags | EV_MORE) : flags);
evaltree(cp->nclist.body, flags);
status = exitstatus;
cp = ncp;
}
@ -966,8 +959,6 @@ evalcommand(union node *cmd, int flgs, struct backcmd *backcmd)
INTOFF;
jp = makejob(cmd, 1);
mode = cmd->ncmd.backgnd;
if (mode)
flags &= ~EV_MORE;
if (flags & EV_BACKCMD) {
mode = FORK_NOJOB;
if (sh_pipe(pip) < 0)
@ -1069,7 +1060,7 @@ evalcommand(union node *cmd, int flgs, struct backcmd *backcmd)
case CMDFUNCTION:
VXTRACE(DBG_EVAL, ("Shell function%s: ",vforked?" VF":""),
trargs(argv));
redirect(cmd->ncmd.redirect, flags & EV_MORE ? REDIR_PUSH : 0);
redirect(cmd->ncmd.redirect, REDIR_PUSH);
saveparam = shellparam;
shellparam.malloc = 0;
shellparam.reset = 1;
@ -1128,8 +1119,7 @@ evalcommand(union node *cmd, int flgs, struct backcmd *backcmd)
freeparam(&shellparam);
shellparam = saveparam;
handler = savehandler;
if (flags & EV_MORE)
popredir();
popredir();
INTON;
if (evalskip == SKIPFUNC) {
evalskip = SKIPNONE;

View File

@ -1,4 +1,4 @@
/* $NetBSD: eval.h,v 1.20 2018/07/25 14:42:50 kre Exp $ */
/* $NetBSD: eval.h,v 1.21 2018/08/19 11:16:13 kre Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -78,4 +78,3 @@ void reset_eval(void);
#define EV_EXIT 0x01 /* exit after evaluating tree */
#define EV_TESTED 0x02 /* exit status is checked; ignore -e flag */
#define EV_BACKCMD 0x04 /* command executing within back quotes */
#define EV_MORE 0x08 /* more commands in this sub-shell */

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.73 2018/01/23 22:12:52 sevan Exp $ */
/* $NetBSD: main.c,v 1.74 2018/08/19 11:16:13 kre Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 1993\
#if 0
static char sccsid[] = "@(#)main.c 8.7 (Berkeley) 7/19/95";
#else
__RCSID("$NetBSD: main.c,v 1.73 2018/01/23 22:12:52 sevan Exp $");
__RCSID("$NetBSD: main.c,v 1.74 2018/08/19 11:16:13 kre Exp $");
#endif
#endif /* not lint */
@ -291,7 +291,7 @@ cmdloop(int top)
} else if (n != NULL && nflag == 0) {
job_warning = (job_warning == 2) ? 1 : 0;
numeof = 0;
evaltree(n, EV_MORE);
evaltree(n, 0);
}
popstackmark(&smark);
setstackmark(&smark);