Skip to content

Commit

Permalink
prevent inf loop on eseq zero-length sep and elt
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Jul 12, 2015
1 parent 4340f7c commit 72e3adf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
17 changes: 17 additions & 0 deletions spec/fabr_eseq_spec.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,23 @@ describe "fabr_eseq()"
context "with zero-length elements and separators"
{
it "works"
{
i.string = "<a,,a>";
i.flags = FABR_F_PRUNE;

t = fabr_eseq("B", &i, _es_sta, _es_el, _es_se, _es_end);

ensure(fabr_tree_to_string(t, i.string, 0) ===f ""
"[ \"B\", 1, 0, 6, null, \"eseq\", 0, [\n"
" [ null, 1, 0, 1, null, \"str\", 1, \"<\" ],\n"
" [ \"e\", 1, 1, 1, null, \"rex\", 2, \"a\" ],\n"
" [ null, 1, 2, 1, null, \"rex\", 2, \",\" ],\n"
" [ \"e\", 1, 3, 0, null, \"rex\", 2, \"\" ],\n"
" [ null, 1, 3, 1, null, \"rex\", 2, \",\" ],\n"
" [ \"e\", 1, 4, 1, null, \"rex\", 2, \"a\" ],\n"
" [ null, 1, 5, 1, null, \"str\", 1, \">\" ]\n"
"] ]");
}
}
}

17 changes: 12 additions & 5 deletions src/aabro.c
Original file line number Diff line number Diff line change
Expand Up @@ -1105,11 +1105,18 @@ fabr_tree *fabr_eseq(

// determine r->result

if (st && st->result == 0) over = 1;
else if (st && st->result == -1) r->result = -1;
else if (st && st->result == 1 && st->length == 0 && et->result == 0) over = 2;
else if (j == 0 && et && et->result == 0 && jseq == 0) over = 1;
else if (et && et->result != 1) r->result = et->result;
if (st && st->result == 0)
over = 1;
else if (st && st->result == -1)
r->result = -1;
else if (st && st->result == 1 && st->length == 0 && et->result == 0)
over = 2;
else if (st && st->result == 1 && st->length == 0 && et->result == 1 && et->length == 0)
over = 2;
else if (j == 0 && et && et->result == 0 && jseq == 0)
over = 1;
else if (et && et->result != 1)
r->result = et->result;

// add or free

Expand Down

0 comments on commit 72e3adf

Please sign in to comment.