regmatch(): add asserts for legal values of nextchr
authorDavid Mitchell <davem@iabyn.com>
Thu, 18 Oct 2012 18:54:20 +0000 (19:54 +0100)
committerDavid Mitchell <davem@iabyn.com>
Fri, 19 Oct 2012 09:50:21 +0000 (10:50 +0100)
nextchr should always hold the next *byte* of the string, or the
special value NEXTCHR_EOS, so assert this. And when we're moving to the
next char, nextchr shouldn't already be NEXTCHR_EOS.

regexec.c

index f25bce1..0ee1c5a 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -3658,6 +3658,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
       reenter_switch:
 
         SET_nextchr;
+        assert(nextchr < 256 && (nextchr >= 0 || nextchr == NEXTCHR_EOS));
 
        switch (state_num) {
        case BOL: /*  /^../  */
@@ -6326,6 +6327,7 @@ NULL
         /* this is a point to jump to in order to increment
          * locinput by one character */
         increment_locinput:
+            assert(!NEXTCHR_IS_EOS);
             if (utf8_target) {
                 locinput += PL_utf8skip[nextchr];
                 /* locinput is allowed to go 1 char off the end, but not 2+ */