Skip to content

Commit

Permalink
regcomp.c: Prevent integer overflow from nested regex quantifiers.
Browse files Browse the repository at this point in the history
(CVE-2020-10543) On 32bit systems the size calculations for nested regular
expression quantifiers could overflow causing heap memory corruption.

Fixes: Perl/perl-security#125
(cherry picked from commit bfd31397db5dc1a5c5d3e0a1f753a4f89a736e71)
  • Loading branch information
John Lightsey authored and steve-m-hay committed May 17, 2020
1 parent 7ece593 commit 897d1f7
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions regcomp.c
Expand Up @@ -5489,6 +5489,12 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode **scanp,
RExC_precomp)));
}

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);
Expand Down

0 comments on commit 897d1f7

Please sign in to comment.