|
|
08805a |
From 58c834052f0985406919de157297e0c340c5b2ed Mon Sep 17 00:00:00 2001
|
|
|
08805a |
From: ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>
|
|
|
08805a |
Date: Fri, 8 Aug 2014 15:22:51 +0000
|
|
|
08805a |
Subject: [PATCH 2/2] Fix compile-time loop for recursive reference within a
|
|
|
08805a |
group with an indefinite repeat.
|
|
|
08805a |
MIME-Version: 1.0
|
|
|
08805a |
Content-Type: text/plain; charset=UTF-8
|
|
|
08805a |
Content-Transfer-Encoding: 8bit
|
|
|
08805a |
|
|
|
08805a |
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@1498 2f5784b3-3f2a-0410-8824-cb99058d5e15
|
|
|
08805a |
Signed-off-by: Petr Písař <ppisar@redhat.com>
|
|
|
08805a |
|
|
|
08805a |
Petr Pisar: Ported to 8.32.
|
|
|
08805a |
|
|
|
08805a |
Signed-off-by: Petr Písař <ppisar@redhat.com>
|
|
|
08805a |
---
|
|
|
08805a |
pcre_compile.c | 17 +++++++----------
|
|
|
08805a |
testdata/testinput1 | 6 ++++++
|
|
|
08805a |
testdata/testoutput1 | 10 ++++++++++
|
|
|
08805a |
3 files changed, 23 insertions(+), 10 deletions(-)
|
|
|
08805a |
|
|
|
08805a |
diff --git a/pcre_compile.c b/pcre_compile.c
|
|
|
08805a |
index ce72527..86cd0c8 100644
|
|
|
08805a |
--- a/pcre_compile.c
|
|
|
08805a |
+++ b/pcre_compile.c
|
|
|
08805a |
@@ -2398,6 +2398,7 @@ for (code = first_significant_code(code + PRIV(OP_lengths)[*code], TRUE);
|
|
|
08805a |
if (c == OP_RECURSE)
|
|
|
08805a |
{
|
|
|
08805a |
const pcre_uchar *scode = cd->start_code + GET(code, 1);
|
|
|
08805a |
+ const pcre_uchar *endgroup = scode;
|
|
|
08805a |
BOOL empty_branch;
|
|
|
08805a |
|
|
|
08805a |
/* Test for forward reference or uncompleted reference. This is disabled
|
|
|
08805a |
@@ -2412,20 +2413,16 @@ for (code = first_significant_code(code + PRIV(OP_lengths)[*code], TRUE);
|
|
|
08805a |
if (GET(scode, 1) == 0) return TRUE; /* Unclosed */
|
|
|
08805a |
}
|
|
|
08805a |
|
|
|
08805a |
- /* If we are scanning a completed pattern, there are no forward references
|
|
|
08805a |
- and all groups are complete. We need to detect whether this is a recursive
|
|
|
08805a |
- call, as otherwise there will be an infinite loop. If it is a recursion,
|
|
|
08805a |
- just skip over it. Simple recursions are easily detected. For mutual
|
|
|
08805a |
- recursions we keep a chain on the stack. */
|
|
|
08805a |
+ /* If the reference is to a completed group, we need to detect whether this
|
|
|
08805a |
+ is a recursive call, as otherwise there will be an infinite loop. If it is
|
|
|
08805a |
+ a recursion, just skip over it. Simple recursions are easily detected. For
|
|
|
08805a |
+ mutual recursions we keep a chain on the stack. */
|
|
|
08805a |
|
|
|
08805a |
+ do endgroup += GET(endgroup, 1); while (*endgroup == OP_ALT);
|
|
|
08805a |
+ if (code >= scode && code <= endgroup) continue; /* Simple recursion */
|
|
|
08805a |
else
|
|
|
08805a |
{
|
|
|
08805a |
recurse_check *r = recurses;
|
|
|
08805a |
- const pcre_uchar *endgroup = scode;
|
|
|
08805a |
-
|
|
|
08805a |
- do endgroup += GET(endgroup, 1); while (*endgroup == OP_ALT);
|
|
|
08805a |
- if (code >= scode && code <= endgroup) continue; /* Simple recursion */
|
|
|
08805a |
-
|
|
|
08805a |
for (r = recurses; r != NULL; r = r->prev)
|
|
|
08805a |
if (r->group == scode) break;
|
|
|
08805a |
if (r != NULL) continue; /* Mutual recursion */
|
|
|
08805a |
diff --git a/testdata/testinput1 b/testdata/testinput1
|
|
|
08805a |
index 3e1061e..c45e1ba 100644
|
|
|
08805a |
--- a/testdata/testinput1
|
|
|
08805a |
+++ b/testdata/testinput1
|
|
|
08805a |
@@ -4967,6 +4967,12 @@ however, we need the complication for Perl. ---/
|
|
|
08805a |
|
|
|
08805a |
/((?(R1)a+|(?1)b))/
|
|
|
08805a |
aaaabcde
|
|
|
08805a |
+
|
|
|
08805a |
+/((?(R)a|(?1)))*/
|
|
|
08805a |
+ aaa
|
|
|
08805a |
+
|
|
|
08805a |
+/((?(R)a|(?1)))+/
|
|
|
08805a |
+ aaa
|
|
|
08805a |
|
|
|
08805a |
/a(*:any
|
|
|
08805a |
name)/K
|
|
|
08805a |
diff --git a/testdata/testoutput1 b/testdata/testoutput1
|
|
|
08805a |
index 5015448..f0eae49 100644
|
|
|
08805a |
--- a/testdata/testoutput1
|
|
|
08805a |
+++ b/testdata/testoutput1
|
|
|
08805a |
@@ -8271,6 +8271,16 @@ MK: M
|
|
|
08805a |
aaaabcde
|
|
|
08805a |
0: aaaab
|
|
|
08805a |
1: aaaab
|
|
|
08805a |
+
|
|
|
08805a |
+/((?(R)a|(?1)))*/
|
|
|
08805a |
+ aaa
|
|
|
08805a |
+ 0: aaa
|
|
|
08805a |
+ 1: a
|
|
|
08805a |
+
|
|
|
08805a |
+/((?(R)a|(?1)))+/
|
|
|
08805a |
+ aaa
|
|
|
08805a |
+ 0: aaa
|
|
|
08805a |
+ 1: a
|
|
|
08805a |
|
|
|
08805a |
/a(*:any
|
|
|
08805a |
name)/K
|
|
|
08805a |
--
|
|
|
08805a |
2.5.5
|
|
|
08805a |
|