Skip to content

Commit

Permalink
Bugfix: avoid out-of-bounds access
Browse files Browse the repository at this point in the history
Avoid out-of-bounds access of symb_code_trans_vect when an unknown
terminal appears in the input (see test19).
  • Loading branch information
TheCount committed Nov 7, 2018
1 parent e346117 commit c362150
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/yaep.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ struct symbs
table. */
struct symb **symb_code_trans_vect;
int symb_code_trans_vect_start;
int symb_code_trans_vect_end;
#endif
};

Expand Down Expand Up @@ -443,10 +444,18 @@ symb_find_by_code (int code)

#ifdef SYMB_CODE_TRANS_VECT
if (symbs_ptr->symb_code_trans_vect != NULL)
return
symbs_ptr->symb_code_trans_vect[code
-
symbs_ptr->symb_code_trans_vect_start];
{
if ((code < symbs_ptr->symb_code_trans_vect_start)
|| (code >= symbs_ptr->symb_code_trans_vect_end))
{
return NULL;
}
else
{
return symbs_ptr->symb_code_trans_vect
[code - symbs_ptr->symb_code_trans_vect_start];
}
}
#endif
symb.term_p = TRUE;
symb.u.term.code = code;
Expand Down Expand Up @@ -598,9 +607,9 @@ symb_finish_adding_terms (void)
if (max_code - min_code < SYMB_CODE_TRANS_VECT_SIZE)
{
symbs_ptr->symb_code_trans_vect_start = min_code;
mem =
yaep_malloc (grammar->alloc,
sizeof (struct symb *) * (max_code - min_code + 1));
symbs_ptr->symb_code_trans_vect_end = max_code + 1;
mem = yaep_malloc (grammar->alloc,
sizeof (struct symb*) * (max_code - min_code + 1));
symbs_ptr->symb_code_trans_vect = (struct symb **) mem;
for (i = 0; (symb = term_get (i)) != NULL; i++)
symbs_ptr->symb_code_trans_vect[symb->u.term.code - min_code] = symb;
Expand Down

0 comments on commit c362150

Please sign in to comment.