683572
From 897d1f7fd515b828e4b198d8b8bef76c6faf03ed Mon Sep 17 00:00:00 2001
683572
From: John Lightsey <jd@cpanel.net>
683572
Date: Wed, 20 Nov 2019 20:02:45 -0600
683572
Subject: [PATCH] regcomp.c: Prevent integer overflow from nested regex
683572
 quantifiers.
683572
MIME-Version: 1.0
683572
Content-Type: text/plain; charset=UTF-8
683572
Content-Transfer-Encoding: 8bit
683572
683572
(CVE-2020-10543) On 32bit systems the size calculations for nested regular
683572
expression quantifiers could overflow causing heap memory corruption.
683572
683572
Fixes: Perl/perl5-security#125
683572
(cherry picked from commit bfd31397db5dc1a5c5d3e0a1f753a4f89a736e71)
683572
Signed-off-by: Petr Písař <ppisar@redhat.com>
683572
---
683572
 regcomp.c | 6 ++++++
683572
 1 file changed, 6 insertions(+)
683572
683572
diff --git a/regcomp.c b/regcomp.c
683572
index 93c8d98fbb..5f86be8086 100644
683572
--- a/regcomp.c
683572
+++ b/regcomp.c
683572
@@ -5489,6 +5489,12 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode **scanp,
683572
 				  RExC_precomp)));
683572
                 }
683572
 
683572
+                if ( ( minnext > 0 && mincount >= SSize_t_MAX / minnext )
683572
+                    || min >= SSize_t_MAX - minnext * mincount )
683572
+                {
683572
+                    FAIL("Regexp out of space");
683572
+                }
683572
+
683572
 		min += minnext * mincount;
683572
 		is_inf_internal |= deltanext == SSize_t_MAX
683572
                          || (maxcount == REG_INFTY && minnext + deltanext > 0);
683572
-- 
683572
2.25.4
683572