diff options
author | Hugo van der Sanden <hv@crypt.org> | 2020-02-12 17:58:56 +0000 |
---|---|---|
committer | Steve Hay <steve.m.hay@googlemail.com> | 2020-02-12 17:59:19 +0000 |
commit | 96c74b2af5e9fdc0fdefecac982aceacec58faa4 (patch) | |
tree | 24fb000c4a6868b4cf72ddb053512d152ecc3177 | |
parent | 3df4e022c7c354ad55f2ee5e104feeb180a23196 (diff) | |
download | perl-96c74b2af5e9fdc0fdefecac982aceacec58faa4.tar.gz |
regexec: don't increment recursion counter for non-postponed EVAL
It wasn't intended to be part of the recursion logic, and doesn't get
decremented again (GH 17490).
(cherry picked from commit af6880c950bceae5aa17dc228f139d0b4e797594)
-rw-r--r-- | regexec.c | 2 | ||||
-rw-r--r-- | t/re/pat.t | 11 |
2 files changed, 11 insertions, 2 deletions
@@ -7243,7 +7243,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog) /* NOTREACHED */ case EVAL: /* /(?{...})B/ /(??{A})B/ and /(?(?{...})X|Y)B/ */ - if (cur_eval && cur_eval->locinput==locinput) { + if (logical == 2 && cur_eval && cur_eval->locinput==locinput) { if ( ++nochange_depth > max_nochange_depth ) Perl_croak(aTHX_ "EVAL without pos change exceeded limit in regex"); } else { diff --git a/t/re/pat.t b/t/re/pat.t index 4ece584840..9338dcc98e 100644 --- a/t/re/pat.t +++ b/t/re/pat.t @@ -25,7 +25,7 @@ BEGIN { skip_all('no re module') unless defined &DynaLoader::boot_DynaLoader; skip_all_without_unicode_tables(); -plan tests => 867; # Update this when adding/deleting tests. +plan tests => 869; # Update this when adding/deleting tests. run_tests() unless caller; @@ -2132,6 +2132,15 @@ SKIP: "Assertion failure matching /il on single char folding to multi"); } + # gh17490: test recursion check + { + my $eval = '(?{1})'; + my $re = sprintf '(?&FOO)(?(DEFINE)(?<FOO>%sfoo))', $eval x 20; + my $result = eval qq{"foo" =~ /$re/}; + is($@ // '', '', "many evals did not die"); + ok($result, "regexp correctly matched"); + } + } # End of sub run_tests 1; |