Blame pcre2-10.33-Fix-partial-matching-bug-in-pcre2_dfa_match.patch

56a2ace
From 427e9b2fffc46d6b49a31df34c8b120bffc2ea60 Mon Sep 17 00:00:00 2001
56a2ace
From: ph10 <ph10@6239d852-aaf2-0410-a92c-79f79f948069>
56a2ace
Date: Wed, 26 Jun 2019 16:13:28 +0000
56a2ace
Subject: [PATCH] Fix partial matching bug in pcre2_dfa_match().
56a2ace
MIME-Version: 1.0
56a2ace
Content-Type: text/plain; charset=UTF-8
56a2ace
Content-Transfer-Encoding: 8bit
56a2ace
56a2ace
git-svn-id: svn://vcs.exim.org/pcre2/code/trunk@1123 6239d852-aaf2-0410-a92c-79f79f948069
56a2ace
Petr Písař: Ported to 10.33.
56a2ace
---
56a2ace
 src/pcre2_dfa_match.c | 11 ++++-----
56a2ace
 testdata/testinput6   | 22 +++++++++++++++++
56a2ace
 testdata/testoutput6  | 36 ++++++++++++++++++++++++++++
56a2ace
56a2ace
diff --git a/src/pcre2_dfa_match.c b/src/pcre2_dfa_match.c
56a2ace
index 911e9b9..538d15d 100644
56a2ace
--- a/src/pcre2_dfa_match.c
56a2ace
+++ b/src/pcre2_dfa_match.c
56a2ace
@@ -3152,8 +3152,8 @@ for (;;)
56a2ace
 
56a2ace
   /* We have finished the processing at the current subject character. If no
56a2ace
   new states have been set for the next character, we have found all the
56a2ace
-  matches that we are going to find. If we are at the top level and partial
56a2ace
-  matching has been requested, check for appropriate conditions.
56a2ace
+  matches that we are going to find. If partial matching has been requested,
56a2ace
+  check for appropriate conditions.
56a2ace
 
56a2ace
   The "forced_ fail" variable counts the number of (*F) encountered for the
56a2ace
   character. If it is equal to the original active_count (saved in
56a2ace
@@ -3165,8 +3165,7 @@ for (;;)
56a2ace
 
56a2ace
   if (new_count <= 0)
56a2ace
     {
56a2ace
-    if (rlevel == 1 &&                               /* Top level, and */
56a2ace
-        could_continue &&                            /* Some could go on, and */
56a2ace
+    if (could_continue &&                            /* Some could go on, and */
56a2ace
         forced_fail != workspace[1] &&               /* Not all forced fail & */
56a2ace
         (                                            /* either... */
56a2ace
         (mb->moptions & PCRE2_PARTIAL_HARD) != 0      /* Hard partial */
56a2ace
@@ -3175,8 +3174,8 @@ for (;;)
56a2ace
          match_count < 0)                            /* no matches */
56a2ace
         ) &&                                         /* And... */
56a2ace
         (
56a2ace
-        partial_newline ||                           /* Either partial NL */
56a2ace
-          (                                          /* or ... */
56a2ace
+        partial_newline ||                     /* Either partial NL */
56a2ace
+          (                                    /* or ... */
56a2ace
           ptr >= end_subject &&                /* End of subject and */
56a2ace
           ptr > mb->start_used_ptr)            /* Inspected non-empty string */
56a2ace
           )
56a2ace
diff --git a/testdata/testinput6 b/testdata/testinput6
56a2ace
index 403e3fa..cc3ebd0 100644
56a2ace
--- a/testdata/testinput6
56a2ace
+++ b/testdata/testinput6
56a2ace
@@ -4972,4 +4972,26 @@
56a2ace
 \= Expect no match
56a2ace
     0
56a2ace
 
56a2ace
+/(?<=pqr)abc(?=xyz)/
56a2ace
+    123pqrabcxy\=ps,allusedtext
56a2ace
+    123pqrabcxyz\=ps,allusedtext
56a2ace
+
56a2ace
+/(?>a+b)/
56a2ace
+    aaaa\=ps
56a2ace
+    aaaab\=ps
56a2ace
+    
56a2ace
+/(abc)(?1)/
56a2ace
+    abca\=ps
56a2ace
+    abcabc\=ps
56a2ace
+
56a2ace
+/(?(?=abc).*|Z)/
56a2ace
+    ab\=ps
56a2ace
+    abcxyz\=ps
56a2ace
+
56a2ace
+/(abc)++x/
56a2ace
+    abcab\=ps
56a2ace
+    abc\=ps 
56a2ace
+    ab\=ps
56a2ace
+    abcx  
56a2ace
+
56a2ace
 # End of testinput6
56a2ace
diff --git a/testdata/testoutput6 b/testdata/testoutput6
56a2ace
index 6a975dd..61cbfe2 100644
56a2ace
--- a/testdata/testoutput6
56a2ace
+++ b/testdata/testoutput6
56a2ace
@@ -7809,4 +7809,40 @@ No match
56a2ace
     0
56a2ace
 No match
56a2ace
 
56a2ace
+/(?<=pqr)abc(?=xyz)/
56a2ace
+    123pqrabcxy\=ps,allusedtext
56a2ace
+Partial match: pqrabcxy
56a2ace
+               <<<
56a2ace
+    123pqrabcxyz\=ps,allusedtext
56a2ace
+ 0: pqrabcxyz
56a2ace
+    <<<   >>>
56a2ace
+
56a2ace
+/(?>a+b)/
56a2ace
+    aaaa\=ps
56a2ace
+Partial match: aaaa
56a2ace
+    aaaab\=ps
56a2ace
+ 0: aaaab
56a2ace
+    
56a2ace
+/(abc)(?1)/
56a2ace
+    abca\=ps
56a2ace
+Partial match: abca
56a2ace
+    abcabc\=ps
56a2ace
+ 0: abcabc
56a2ace
+
56a2ace
+/(?(?=abc).*|Z)/
56a2ace
+    ab\=ps
56a2ace
+Partial match: ab
56a2ace
+    abcxyz\=ps
56a2ace
+ 0: abcxyz
56a2ace
+
56a2ace
+/(abc)++x/
56a2ace
+    abcab\=ps
56a2ace
+Partial match: abcab
56a2ace
+    abc\=ps 
56a2ace
+Partial match: abc
56a2ace
+    ab\=ps
56a2ace
+Partial match: ab
56a2ace
+    abcx  
56a2ace
+ 0: abcx
56a2ace
+
56a2ace
 # End of testinput6
56a2ace
-- 
56a2ace
2.20.1
56a2ace