]> granicus.if.org Git - flex/commitdiff
scanner: temporarily protect against ccl overflow & overwriting.
authorExplorer09 <explorer09@gmail.com>
Fri, 13 Oct 2017 16:31:01 +0000 (00:31 +0800)
committerWill Estes <westes575@gmail.com>
Tue, 28 Nov 2017 19:56:42 +0000 (14:56 -0500)
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.)

src/ccl.c

index ff9a2134ee33f80839d63a18cc4f099d92bdec39..5c5af13550fa9d9b9ab14c82a0b852d5c8f1cf1a 100644 (file)
--- a/src/ccl.c
+++ b/src/ccl.c
@@ -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;