diff options
author | John Lightsey <jd@cpanel.net> | 2019-11-20 20:02:45 -0600 |
---|---|---|
committer | Steve Hay <steve.m.hay@googlemail.com> | 2020-05-17 10:34:13 +0100 |
commit | 1aef74e6bc0269fcd6ad7669fcd58488ffaf736f (patch) | |
tree | bda6d89a666fd8b22180d629f5f63c04c9d3bcfd | |
parent | 304732faad5ed2757303dec1c9574bfc191cf398 (diff) | |
download | perl-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.c | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -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); |