@@ -2640,7 +2640,11 @@ S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog)
2640
2640
2641
2641
bool result = 0 ; /* return value of S_regmatch */
2642
2642
int depth = 0 ; /* depth of backtrack stack */
2643
- int nochange_depth = 0 ; /* depth of GOSUB recursion with nochange*/
2643
+ U32 nochange_depth = 0 ; /* depth of GOSUB recursion with nochange */
2644
+ const U32 max_nochange_depth =
2645
+ (3 * rex -> nparens > MAX_RECURSE_EVAL_NOCHANGE_DEPTH ) ?
2646
+ 3 * rex -> nparens : MAX_RECURSE_EVAL_NOCHANGE_DEPTH ;
2647
+
2644
2648
regmatch_state * yes_state = NULL ; /* state to pop to on success of
2645
2649
subpattern */
2646
2650
/* mark_state piggy backs on the yes_state logic so that when we unwind
@@ -3568,7 +3572,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog)
3568
3572
if (cur_eval && cur_eval -> locinput == locinput ) {
3569
3573
if (cur_eval -> u .eval .close_paren == (U32 )ARG (scan ))
3570
3574
Perl_croak (aTHX_ "Infinite recursion in regex" );
3571
- if ( ++ nochange_depth > MAX_RECURSE_EVAL_NOCHANGE_DEPTH )
3575
+ if ( ++ nochange_depth > max_nochange_depth )
3572
3576
Perl_croak (aTHX_
3573
3577
"Pattern subroutine nesting without pos change"
3574
3578
" exceeded limit in regex" );
@@ -3589,7 +3593,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog)
3589
3593
/* NOTREACHED */
3590
3594
case EVAL : /* /(?{A})B/ /(??{A})B/ and /(?(?{A})X|Y)B/ */
3591
3595
if (cur_eval && cur_eval -> locinput == locinput ) {
3592
- if ( ++ nochange_depth > MAX_RECURSE_EVAL_NOCHANGE_DEPTH )
3596
+ if ( ++ nochange_depth > max_nochange_depth )
3593
3597
Perl_croak (aTHX_ "EVAL without pos change exceeded limit in regex" );
3594
3598
} else {
3595
3599
nochange_depth = 0 ;
@@ -3738,6 +3742,8 @@ S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog)
3738
3742
cur_curlyx = ST .prev_curlyx ;
3739
3743
/* XXXX This is too dramatic a measure... */
3740
3744
PL_reg_maxiter = 0 ;
3745
+ if ( nochange_depth > 0 );
3746
+ nochange_depth -- ;
3741
3747
sayYES ;
3742
3748
3743
3749
@@ -3754,6 +3760,8 @@ S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog)
3754
3760
cur_curlyx = ST .prev_curlyx ;
3755
3761
/* XXXX This is too dramatic a measure... */
3756
3762
PL_reg_maxiter = 0 ;
3763
+ if ( nochange_depth > 0 );
3764
+ nochange_depth -- ;
3757
3765
sayNO_SILENT ;
3758
3766
#undef ST
3759
3767
@@ -4774,6 +4782,8 @@ NULL
4774
4782
DEBUG_EXECUTE_r (
4775
4783
PerlIO_printf (Perl_debug_log , "%*s EVAL trying tail ... %" UVxf "\n" ,
4776
4784
REPORT_CODE_OFF + depth * 2 , "" ,PTR2UV (cur_eval )););
4785
+ if ( nochange_depth > 0 );
4786
+ nochange_depth ++ ;
4777
4787
PUSH_YES_STATE_GOTO (EVAL_AB ,
4778
4788
st -> u .eval .prev_eval -> u .eval .B ); /* match B */
4779
4789
}
0 commit comments