Blame SOURCES/perl-5.24.0-fix-128109-do-not-move-RExC_open_parens-0-in-reginse.patch

276c98
From c6e7032a63f2162405644582af6600dcb5ba66d1 Mon Sep 17 00:00:00 2001
276c98
From: Yves Orton <demerphq@gmail.com>
276c98
Date: Tue, 10 May 2016 09:44:31 +0200
276c98
Subject: [PATCH] fix #128109 - do not move RExC_open_parens[0] in reginsert
276c98
MIME-Version: 1.0
276c98
Content-Type: text/plain; charset=UTF-8
276c98
Content-Transfer-Encoding: 8bit
276c98
276c98
Petr Pisar: Two commits ported to 5.24.0:
276c98
276c98
commit da7cf1cc7cedc01f35ceb6724e8260c3b0ee0d12
276c98
Author: Yves Orton <demerphq@gmail.com>
276c98
Date:   Tue May 10 09:44:31 2016 +0200
276c98
276c98
    fix #128109 - do not move RExC_open_parens[0] in reginsert
276c98
276c98
    In d5a00e4af6b155495be31a35728b8fef8e671ebe I merged GOSUB and GOSTART,
276c98
    part of which involved making RExC_open_parens[0] refer to the start of
276c98
    the pattern, and RExC_close_parens[0] referring to the end of the pattern.
276c98
276c98
    This tripped up in reginsert in a subtle way, the start of the pattern
276c98
    cannot and should not move in reginsert(). Unlike a paren that might
276c98
    be at the start of the pattern which should move when something is inserted
276c98
    in front of it, the start is a fixed point and should never move.
276c98
276c98
    This patches fixes this up, and adds an assert to check that reginsert()
276c98
    is not called once study_chunk() starts, as reginsert() does not adjust
276c98
    RExC_recurse.
276c98
276c98
    This was noticed by hv while debugging [perl #128085], thanks hugo!
276c98
276c98
commit ec5bd2262bb4e28f0dc6a0a3edb9b1f1b5befa2f
276c98
Author: Dan Collins <dcollinsn@gmail.com>
276c98
Date:   Fri Jun 17 19:40:57 2016 -0400
276c98
276c98
    Add tests for regex recursion
276c98
276c98
    d5a00e4af introduced a bug in reginsert that was fixed by da7cf1cc7,
276c98
    originally documented in [perl #128109]. This patch adds two
276c98
    regression tests for the testcase reported by Jan Goyvaerts in
276c98
    [perl #128420].
276c98
276c98
Signed-off-by: Petr Písař <ppisar@redhat.com>
276c98
---
276c98
 regcomp.c     | 13 +++++++++++--
276c98
 t/re/re_tests |  2 ++
276c98
 2 files changed, 13 insertions(+), 2 deletions(-)
276c98
276c98
diff --git a/regcomp.c b/regcomp.c
276c98
index f29892c..7462885 100644
276c98
--- a/regcomp.c
276c98
+++ b/regcomp.c
276c98
@@ -223,6 +223,7 @@ struct RExC_state_t {
276c98
 #endif
276c98
     bool        seen_unfolded_sharp_s;
276c98
     bool        strict;
276c98
+    bool        study_started;
276c98
 };
276c98
 
276c98
 #define RExC_flags	(pRExC_state->flags)
276c98
@@ -289,6 +290,7 @@ struct RExC_state_t {
276c98
 #define RExC_frame_last (pRExC_state->frame_last)
276c98
 #define RExC_frame_count (pRExC_state->frame_count)
276c98
 #define RExC_strict (pRExC_state->strict)
276c98
+#define RExC_study_started      (pRExC_state->study_started)
276c98
 #define RExC_warn_text (pRExC_state->warn_text)
276c98
 
276c98
 /* Heuristic check on the complexity of the pattern: if TOO_NAUGHTY, we set
276c98
@@ -4104,6 +4106,7 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode **scanp,
276c98
     GET_RE_DEBUG_FLAGS_DECL;
276c98
 
276c98
     PERL_ARGS_ASSERT_STUDY_CHUNK;
276c98
+    RExC_study_started= 1;
276c98
 
276c98
 
276c98
     if ( depth == 0 ) {
276c98
@@ -6886,6 +6889,7 @@ Perl_re_op_compile(pTHX_ SV ** const patternp, int pat_count,
276c98
     RExC_contains_locale = 0;
276c98
     RExC_contains_i = 0;
276c98
     RExC_strict = cBOOL(pm_flags & RXf_PMf_STRICT);
276c98
+    RExC_study_started = 0;
276c98
     pRExC_state->runtime_code_qr = NULL;
276c98
     RExC_frame_head= NULL;
276c98
     RExC_frame_last= NULL;
276c98
@@ -18240,7 +18244,9 @@ S_reginsert(pTHX_ RExC_state_t *pRExC_state, U8 op, regnode *opnd, U32 depth)
276c98
 	RExC_size += size;
276c98
 	return;
276c98
     }
276c98
-
276c98
+    assert(!RExC_study_started); /* I believe we should never use reginsert once we have started
276c98
+                                    studying. If this is wrong then we need to adjust RExC_recurse
276c98
+                                    below like we do with RExC_open_parens/RExC_close_parens. */
276c98
     src = RExC_emit;
276c98
     RExC_emit += size;
276c98
     dst = RExC_emit;
276c98
@@ -18251,7 +18257,10 @@ S_reginsert(pTHX_ RExC_state_t *pRExC_state, U8 op, regnode *opnd, U32 depth)
276c98
          * iow it is 1 more than the number of parens seen in
276c98
          * the pattern so far. */
276c98
         for ( paren=0 ; paren < RExC_npar ; paren++ ) {
276c98
-            if ( RExC_open_parens[paren] >= opnd ) {
276c98
+            /* note, RExC_open_parens[0] is the start of the
276c98
+             * regex, it can't move. RExC_close_parens[0] is the end
276c98
+             * of the regex, it *can* move. */
276c98
+            if ( paren && RExC_open_parens[paren] >= opnd ) {
276c98
                 /*DEBUG_PARSE_FMT("open"," - %d",size);*/
276c98
                 RExC_open_parens[paren] += size;
276c98
             } else {
276c98
diff --git a/t/re/re_tests b/t/re/re_tests
276c98
index 34ac94a..7e8522d 100644
276c98
--- a/t/re/re_tests
276c98
+++ b/t/re/re_tests
276c98
@@ -1966,6 +1966,8 @@ ab(?#Comment){2}c	abbc	y	$&	abbc
276c98
 .{1}??	-	c	-	Nested quantifiers
276c98
 .{1}?+	-	c	-	Nested quantifiers
276c98
 (?:.||)(?|)000000000@	000000000@	y	$&	000000000@		#  [perl #126405]
276c98
+aa$|a(?R)a|a	aaa	y	$&	aaa		# [perl 128420] recursive matches
276c98
+(?:\1|a)([bcd])\1(?:(?R)|e)\1	abbaccaddedcb	y	$&	abbaccaddedcb		# [perl 128420] recursive match with backreferences
276c98
 
276c98
 # Keep these lines at the end of the file
276c98
 # vim: softtabstop=0 noexpandtab
276c98
-- 
276c98
2.5.5
276c98