Skip to content

Commit

Permalink
Fix parser crash with recursive goal expansion, re issue #610
Browse files Browse the repository at this point in the history
  • Loading branch information
infradig committed Oct 21, 2024
1 parent aa4feb4 commit 4baf791
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1968,6 +1968,14 @@ static cell *goal_expansion(parser *p, cell *goal)
p2->skip = true;
p2->srcptr = SB_cstr(s);
tokenize(p2, false, false);

if (p2->error) {
parser_destroy(p2);
query_destroy(q);
p->error = true;
return goal;
}

xref_clause(p2->m, p2->cl, NULL);
execute(q, p2->cl->cells, p2->cl->nbr_vars);
SB_free(s);
Expand Down Expand Up @@ -2021,6 +2029,14 @@ static cell *goal_expansion(parser *p, cell *goal)
p2->reuse = true;
p2->srcptr = src;
tokenize(p2, false, false);

if (p2->error) {
parser_destroy(p2);
query_destroy(q);
p->error = true;
return goal;
}

xref_clause(p2->m, p2->cl, NULL);
free(src);

Expand Down Expand Up @@ -3390,6 +3406,8 @@ unsigned tokenize(parser *p, bool is_arg_processing, bool is_consing)

assign_vars(p, p->read_term_slots, false);

if (p->error) return 0;

if (p->consulting && check_body_callable(p->cl->cells)) {
if (DUMP_ERRS || !p->do_read_term)
printf("Error: type error, not callable, %s:%d\n", get_loaded(p->m, p->m->filename), p->line_nbr);
Expand Down

0 comments on commit 4baf791

Please sign in to comment.