summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorExplorer09 <explorer09@gmail.com>2017-10-14 00:31:01 +0800
committerWill Estes <westes575@gmail.com>2017-11-28 14:56:42 -0500
commit12d2f8608046c5d43646e3c1dc277c0a2914ae1b (patch)
treea15b0d9177867becbe5e7e006e9e9a3227f67a9f
parentea1faa2d09693cf7f3a3c3c79a5ddb7fbd0d3ba5 (diff)
scanner: temporarily protect against ccl overflow & overwriting.
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.)
-rw-r--r--src/ccl.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/ccl.c b/src/ccl.c
index ff9a213..5c5af13 100644
--- 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;