restore yyrecursive context in quitenv (LP#1069428)

This commit is contained in:
tg 2012-10-30 20:07:15 +00:00
parent fc27886680
commit faa0a78df3
4 changed files with 52 additions and 20 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.562 2012/10/22 20:19:10 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.563 2012/10/30 20:07:10 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -29,7 +29,7 @@
# http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD
expected-stdout:
@(#)MIRBSD KSH R40 2012/10/22
@(#)MIRBSD KSH R40 2012/10/30
description:
Check version of shell.
stdin:
@ -38,7 +38,7 @@ name: KSH_VERSION
category: shell:legacy-no
---
expected-stdout:
@(#)LEGACY KSH R40 2012/10/22
@(#)LEGACY KSH R40 2012/10/30
description:
Check version of legacy shell.
stdin:

5
main.c
View File

@ -34,7 +34,7 @@
#include <locale.h>
#endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.234 2012/10/30 20:07:00 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.235 2012/10/30 20:07:12 tg Exp $");
extern char **environ;
@ -925,6 +925,7 @@ newenv(int type)
ep->loc = e->loc;
ep->savefd = NULL;
ep->temps = NULL;
ep->yyrecursive_statep = NULL;
ep->type = type;
ep->flags = 0;
/* jump buffer is invalid because flags == 0 */
@ -938,6 +939,8 @@ quitenv(struct shf *shf)
char *cp;
int fd;
while (e->yyrecursive_statep)
yyrecursive_pop();
if (ep->oenv && ep->oenv->loc != ep->loc)
popblock();
if (ep->savefd != NULL) {

9
sh.h
View File

@ -157,9 +157,9 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.597 2012/10/22 20:19:16 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.598 2012/10/30 20:07:13 tg Exp $");
#endif
#define MKSH_VERSION "R40 2012/10/22"
#define MKSH_VERSION "R40 2012/10/30"
/* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES
@ -646,6 +646,8 @@ enum sh_flag {
#define kshlongjmp siglongjmp
#endif
struct yyrecursive_state;
extern struct env {
ALLOC_ITEM alloc_INT; /* internal, do not touch */
Area area; /* temporary allocation area */
@ -653,6 +655,8 @@ extern struct env {
struct block *loc; /* local variables and functions */
short *savefd; /* original redirected fds */
struct temp *temps; /* temp files */
/* saved parser recursion state */
struct yyrecursive_state *yyrecursive_statep;
kshjmp_buf jbuf; /* long jump back to env creator */
uint8_t type; /* environment type - see below */
uint8_t flags; /* EF_* */
@ -1929,6 +1933,7 @@ void initkeywords(void);
struct op *compile(Source *, bool);
bool parse_usec(const char *, struct timeval *);
char *yyrecursive(int);
void yyrecursive_pop(void);
/* tree.c */
void fptreef(struct shf *, int, const char *, ...);
char *snptreef(char *, ssize_t, const char *, ...);

52
syn.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.82 2012/10/22 20:19:18 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.83 2012/10/30 20:07:15 tg Exp $");
extern int subshell_nesting_type;
extern void yyskiputf8bom(void);
@ -33,6 +33,15 @@ struct nesting_state {
int start_line; /* line nesting began on */
};
struct yyrecursive_state {
struct yyrecursive_state *next;
struct ioword **old_herep;
int old_symbol;
int old_salias;
int old_nesting_type;
bool old_reject;
};
static void yyparse(void);
static struct op *pipeline(int);
static struct op *andor(void);
@ -1122,9 +1131,7 @@ yyrecursive(int subtype MKSH_A_UNUSED)
{
struct op *t;
char *cp;
bool old_reject;
int old_symbol, old_salias, old_nesting_type;
struct ioword **old_herep;
struct yyrecursive_state *ys;
int stok, etok;
#ifndef MKSH_DISABLE_EXPERIMENTAL
@ -1138,28 +1145,45 @@ yyrecursive(int subtype MKSH_A_UNUSED)
etok = ')';
}
ys = alloc(sizeof(struct yyrecursive_state), ATEMP);
/* tell the lexer to accept a closing parenthesis as EOD */
old_nesting_type = subshell_nesting_type;
ys->old_nesting_type = subshell_nesting_type;
subshell_nesting_type = etok;
/* push reject state, parse recursively, pop reject state */
old_reject = reject;
old_symbol = symbol;
ys->old_reject = reject;
ys->old_symbol = symbol;
ACCEPT;
old_herep = herep;
old_salias = sALIAS;
ys->old_herep = herep;
ys->old_salias = sALIAS;
sALIAS = 0;
ys->next = e->yyrecursive_statep;
e->yyrecursive_statep = ys;
/* we use TPAREN as a helper container here */
t = nested(TPAREN, stok, etok);
sALIAS = old_salias;
herep = old_herep;
reject = old_reject;
symbol = old_symbol;
yyrecursive_pop();
/* t->left because nested(TPAREN, ...) hides our goodies there */
cp = snptreef(NULL, 0, "%T", t->left);
tfree(t, ATEMP);
subshell_nesting_type = old_nesting_type;
return (cp);
}
void
yyrecursive_pop(void)
{
struct yyrecursive_state *ys = e->yyrecursive_statep;
e->yyrecursive_statep = ys->next;
sALIAS = ys->old_salias;
herep = ys->old_herep;
reject = ys->old_reject;
symbol = ys->old_symbol;
subshell_nesting_type = ys->old_nesting_type;
afree(ys, ATEMP);
}