Blob Blame History Raw
From 86ecc4da0ec0cea8f9b6af4191b87e4c454aa17c Mon Sep 17 00:00:00 2001
From: Yves Orton <demerphq@gmail.com>
Date: Sun, 10 Sep 2017 10:59:05 +0200
Subject: [PATCH] fix #132017 - OPFAIL insert needs to set flags to 0
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

why reginsert doesnt do this stuff I dont know.

Petr Písař: Ported to 5.24.3.

Signed-off-by: Petr Písař <ppisar@redhat.com>
---
 regcomp.c  | 6 +++++-
 t/re/pat.t | 5 ++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/regcomp.c b/regcomp.c
index 6dcc58a..374032c 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -11498,6 +11498,7 @@ S_regpiece(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
             if (max < min) {    /* If can't match, warn and optimize to fail
                                    unconditionally */
                 reginsert(pRExC_state, OPFAIL, orig_emit, depth+1);
+                orig_emit->flags = 0;
                 if (PASS2) {
                     ckWARNreg(RExC_parse, "Quantifier {n,m} with n > m can't match");
                     NEXT_OFF(orig_emit)= regarglen[OPFAIL] + NODE_STEP_REGNODE;
@@ -19046,8 +19047,11 @@ Perl_regprop(pTHX_ const regexp *prog, SV *sv, const regnode *o, const regmatch_
 
     /* add on the verb argument if there is one */
     if ( ( k == VERB || OP(o) == ACCEPT || OP(o) == OPFAIL ) && o->flags) {
-        Perl_sv_catpvf(aTHX_ sv, ":%"SVf,
+        if ( ARG(o) )
+            Perl_sv_catpvf(aTHX_ sv, ":%" SVf,
                        SVfARG((MUTABLE_SV(progi->data->data[ ARG( o ) ]))));
+        else
+            sv_catpvs(sv, ":NULL");
     }
 #else
     PERL_UNUSED_CONTEXT;
diff --git a/t/re/pat.t b/t/re/pat.t
index 007f11d..6ff8b0b 100644
--- a/t/re/pat.t
+++ b/t/re/pat.t
@@ -23,7 +23,7 @@ BEGIN {
     skip_all_without_unicode_tables();
 }
 
-plan tests => 794;  # Update this when adding/deleting tests.
+plan tests => 795;  # Update this when adding/deleting tests.
 
 run_tests() unless caller;
 
@@ -1793,6 +1793,9 @@ EOP
         pos($text) = 3;
         ok(scalar($text !~ m{(~*=[a-z]=)}g), "RT #131575");
     }
+    {
+        fresh_perl_is('"AA" =~ m/AA{1,0}/','',{},"handle OPFAIL insert properly");
+    }
 
 } # End of sub run_tests
 
-- 
2.13.6