[Pcre-svn] [1513] code/trunk: Fix zero-repeat assertion cond…

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [1513] code/trunk: Fix zero-repeat assertion condition bug.
Revision: 1513
          http://vcs.pcre.org/viewvc?view=rev&revision=1513
Author:   ph10
Date:     2014-11-19 20:57:13 +0000 (Wed, 19 Nov 2014)


Log Message:
-----------
Fix zero-repeat assertion condition bug.

Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/pcre_exec.c
    code/trunk/testdata/testinput2
    code/trunk/testdata/testoutput2


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2014-11-09 07:27:16 UTC (rev 1512)
+++ code/trunk/ChangeLog    2014-11-19 20:57:13 UTC (rev 1513)
@@ -10,6 +10,9 @@
     capture so far and the currrent group as "unset". Thus, the ovector for 
     those groups contained whatever was previously there. An example is the 
     pattern /(x)|((*ACCEPT))/ when matched against "abcd".
+    
+2.  If an assertion condition was quantified with a minimum of zero (an odd 
+    thing to do, but it happened), SIGSEGV or other misbehaviour could occur. 





Modified: code/trunk/pcre_exec.c
===================================================================
--- code/trunk/pcre_exec.c    2014-11-09 07:27:16 UTC (rev 1512)
+++ code/trunk/pcre_exec.c    2014-11-19 20:57:13 UTC (rev 1513)
@@ -1404,8 +1404,11 @@
         condition = TRUE;


         /* Advance ecode past the assertion to the start of the first branch,
-        but adjust it so that the general choosing code below works. */
-
+        but adjust it so that the general choosing code below works. If the 
+        assertion has a quantifier that allows zero repeats we must skip over 
+        the BRAZERO. This is a lunatic thing to do, but somebody did! */
+        
+        if (*ecode == OP_BRAZERO) ecode++; 
         ecode += GET(ecode, 1);
         while (*ecode == OP_ALT) ecode += GET(ecode, 1);
         ecode += 1 + LINK_SIZE - PRIV(OP_lengths)[condcode];


Modified: code/trunk/testdata/testinput2
===================================================================
--- code/trunk/testdata/testinput2    2014-11-09 07:27:16 UTC (rev 1512)
+++ code/trunk/testdata/testinput2    2014-11-19 20:57:13 UTC (rev 1513)
@@ -4078,4 +4078,10 @@


/\x{whatever}/

+"((?=(?(?=(?(?=(?(?=())))*)))))"
+    a
+
+"(?(?=)?==)(((((((((?=)))))))))"
+    a
+
 /-- End of testinput2 --/


Modified: code/trunk/testdata/testoutput2
===================================================================
--- code/trunk/testdata/testoutput2    2014-11-09 07:27:16 UTC (rev 1512)
+++ code/trunk/testdata/testoutput2    2014-11-19 20:57:13 UTC (rev 1513)
@@ -14206,4 +14206,14 @@
 /\x{whatever}/
 Failed: non-hex character in \x{} (closing brace missing?) at offset 3


+"((?=(?(?=(?(?=(?(?=())))*)))))"
+    a
+ 0: 
+ 1: 
+ 2: 
+
+"(?(?=)?==)(((((((((?=)))))))))"
+    a
+No match
+
 /-- End of testinput2 --/