From 61e2c0af14d6f848fd8f2ca85beeeb8363365321 Mon Sep 17 00:00:00 2001 From: Yves Orton Date: Fri, 13 Jan 2023 18:23:01 +0100 Subject: regexec.c - avoid calling regrepeat when the max is 0 When we have a max quantifier of 0, then the quantified item is essentially a NOTHING reop. Regardless, we do not need to call regrepeat, and doing so confuses some of the logic it contains. Simply avoiding calling regrepeat() fixes the underlying issue, and avoids the broken code. This fixes GH Issue #20690. --- regexec.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'regexec.c') diff --git a/regexec.c b/regexec.c index a521ae3013..84f2670e6d 100644 --- a/regexec.c +++ b/regexec.c @@ -9316,7 +9316,10 @@ NULL /* avoid taking address of locinput, so it can remain * a register var */ char *li = locinput; - ST.count = regrepeat(rex, &li, ST.A, loceol, reginfo, ST.max); + if (ST.max) + ST.count = regrepeat(rex, &li, ST.A, loceol, reginfo, ST.max); + else + ST.count = 0; if (ST.count < ST.min) sayNO; SET_locinput(li); @@ -10058,6 +10061,8 @@ S_regrepeat(pTHX_ regexp *prog, char **startposp, const regnode *p, unsigned int to_complement = 0; /* Invert the result? */ char_class_number_ classnum; + assert(max); + PERL_ARGS_ASSERT_REGREPEAT; /* This routine is structured so that we switch on the input OP. Each OP -- cgit v1.2.1