do not overflow when the pattern is unbounded
authorYves Orton <yves.orton@booking.com>
Tue, 4 Feb 2014 08:18:16 +0000 (16:18 +0800)
committerYves Orton <yves.orton@booking.com>
Tue, 4 Feb 2014 09:01:36 +0000 (17:01 +0800)
regcomp.c

index 92e3ef4..ba63f1f 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -5394,10 +5394,9 @@ PerlIO_printf(Perl_debug_log, "LHS=%"UVdf" RHS=%"UVdf"\n",
     {
         SSize_t final_minlen= min < stopmin ? min : stopmin;
 
-        if (RExC_maxlen < final_minlen + delta) {
+        if (!(RExC_seen & REG_UNBOUNDED_QUANTIFIER_SEEN) && (RExC_maxlen < final_minlen + delta)) {
             RExC_maxlen = final_minlen + delta;
         }
-
         return final_minlen;
     }
     /* not-reached */
@@ -7030,6 +7029,14 @@ reStudy:
        }
     }
 
+    if (RExC_seen & REG_UNBOUNDED_QUANTIFIER_SEEN) {
+        r->extflags |= RXf_UNBOUNDED_QUANTIFIER_SEEN;
+        r->maxlen = REG_INFTY;
+    }
+    else {
+        r->maxlen = RExC_maxlen;
+    }
+
     /* Guard against an embedded (?=) or (?<=) with a longer minlen than
        the "real" pattern. */
     DEBUG_OPTIMISE_r({
@@ -7040,8 +7047,6 @@ reStudy:
     if (r->minlen < minlen)
         r->minlen = minlen;
 
-
-
     if (RExC_seen & REG_GPOS_SEEN)
         r->intflags |= PREGf_GPOS_SEEN;
     if (RExC_seen & REG_LOOKBEHIND_SEEN)
@@ -7065,9 +7070,6 @@ reStudy:
     else
         RXp_PAREN_NAMES(r) = NULL;
 
-    if (RExC_seen & REG_UNBOUNDED_QUANTIFIER_SEEN)
-        r->extflags |= RXf_UNBOUNDED_QUANTIFIER_SEEN;
-
     /* If we have seen an anchor in our pattern then we set the extflag RXf_IS_ANCHORED
      * so it can be used in pp.c */
     if (r->intflags & PREGf_ANCH)