Skip to content

Commit

Permalink
Exceptions may be raised in yyparse(); fix #3600
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Apr 12, 2017
1 parent 918e7bb commit 326e043
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
26 changes: 22 additions & 4 deletions mrbgems/mruby-compiler/core/parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -5514,18 +5514,37 @@ void mrb_parser_dump(mrb_state *mrb, node *tree, int offset);
MRB_API void
mrb_parser_parse(parser_state *p, mrbc_context *c)
{
struct mrb_jmpbuf buf;
p->jmp = &buf;
struct mrb_jmpbuf buf1;
p->jmp = &buf1;

MRB_TRY(p->jmp) {
int n;

p->cmd_start = TRUE;
p->in_def = p->in_single = 0;
p->nerr = p->nwarn = 0;
p->lex_strterm = NULL;

parser_init_cxt(p, c);
if (yyparse(p) != 0 || p->nerr > 0) {

if (p->mrb->jmp) {
n = yyparse(p);
}
else {
struct mrb_jmpbuf buf2;

p->mrb->jmp = &buf2;
MRB_TRY(p->mrb->jmp) {
n = yyparse(p);
}
MRB_CATCH(p->mrb->jmp) {
p->nerr++;
mrb_p(p->mrb, mrb_obj_value(p->mrb->exc));
}
MRB_END_EXC(p->mrb->jmp);
p->mrb->jmp = 0;
}
if (n != 0 || p->nerr > 0) {
p->tree = 0;
return;
}
Expand All @@ -5536,7 +5555,6 @@ mrb_parser_parse(parser_state *p, mrbc_context *c)
if (c && c->dump_result) {
mrb_parser_dump(p->mrb, p->tree, 0);
}

}
MRB_CATCH(p->jmp) {
yyerror(p, "memory allocation error");
Expand Down
1 change: 1 addition & 0 deletions src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ mrb_funcall_with_block(mrb_state *mrb, mrb_value self, mrb_sym mid, mrb_int argc
val = mrb_obj_value(mrb->exc);
}
MRB_END_EXC(&c_jmp);
mrb->jmp = 0;
}
else {
struct RProc *p;
Expand Down

0 comments on commit 326e043

Please sign in to comment.