Skip to content

Commit

Permalink
scanner: temporarily protect against ccl overflow & overwriting.
Browse files Browse the repository at this point in the history
For ccladd(), if cclp given is a non-last ccl, adding a char into it
will overflow the buffer and overwrite the first char in the next ccl.

For now, add a temporary detection and protection code.  (Not sure if
this could happen in user input, but if it could, then you can expect
some "corrupted" behavior for generated scanners.)
  • Loading branch information
Explorer09 authored and westes committed Nov 28, 2017
1 parent ea1faa2 commit 12d2f86
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/ccl.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ void ccladd (int cclp, int ch)

newpos = ind + len;

/* For a non-last cclp, expanding the set will overflow and overwrite a
* char in the next cclp.
* FIXME: Need another allocation scheme for ccl's. */
if (cclp != lastccl) {
flexfatal(_("internal error: trying to add a char to a non-last ccl.\n"));
}

if (newpos >= current_max_ccl_tbl_size) {
current_max_ccl_tbl_size += MAX_CCL_TBL_SIZE_INCREMENT;

Expand Down

0 comments on commit 12d2f86

Please sign in to comment.