[pcre-dev] PCRE 7.x fails compilation of patterns with optio…

Top Page
Delete this message
Author: Viktor Griph
Date:  
To: pcre-dev
Subject: [pcre-dev] PCRE 7.x fails compilation of patterns with optional branches in branches
Hi.

Patterns like /(.*(.)?)*/ will make pcre_match not terminate on a match.

I've located the eerror to incorrect assumption that branch 1 might not
be empty. The attached patch against v7.1 should fix the problem.

/Viktor--- pcre_compile.c~    2007-04-17 10:21:58.000000000 +0200
+++ pcre_compile.c    2007-05-31 16:35:31.000000000 +0200
@@ -1370,6 +1370,19 @@
 
   c = *code;
 
+  if (c == OP_BRAZERO || c == OP_BRAMINZERO)
+    {
+      /* Skip over the sub branch, it can be empty */
+      code = code + _pcre_OP_lengths[c];
+      do
+    {
+      code += GET(code, 1);
+    }
+      while (*code == OP_ALT);
+      c = *code;
+      continue;
+    }
+
   if (c == OP_BRA || c == OP_CBRA || c == OP_ONCE)
     {
     BOOL empty_branch;