summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Lightsey <jd@cpanel.net>2019-11-20 20:02:45 -0600
committerSteve Hay <steve.m.hay@googlemail.com>2020-05-17 10:34:13 +0100
commit1aef74e6bc0269fcd6ad7669fcd58488ffaf736f (patch)
treebda6d89a666fd8b22180d629f5f63c04c9d3bcfd
parent304732faad5ed2757303dec1c9574bfc191cf398 (diff)
downloadperl-1aef74e6bc0269fcd6ad7669fcd58488ffaf736f.tar.gz
regcomp.c: Prevent integer overflow from nested regex quantifiers.
(CVE-2020-10543) On 32bit systems the size calculations for nested regular expression quantifiers could overflow causing heap memory corruption. Fixes: Perl/perl5-security#125 (cherry picked from commit 208dea486fa24081cbc0cf05fa5a15c802e2bc68)
-rw-r--r--regcomp.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/regcomp.c b/regcomp.c
index e1da15a77c..dd18add1db 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -5181,6 +5181,12 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode **scanp,
(void)ReREFCNT_inc(RExC_rx_sv);
}
+ if ( ( minnext > 0 && mincount >= SSize_t_MAX / minnext )
+ || min >= SSize_t_MAX - minnext * mincount )
+ {
+ FAIL("Regexp out of space");
+ }
+
min += minnext * mincount;
is_inf_internal |= deltanext == SSize_t_MAX
|| (maxcount == REG_INFTY && minnext + deltanext > 0);