8e746e
From 208dea486fa24081cbc0cf05fa5a15c802e2bc68 Mon Sep 17 00:00:00 2001
8e746e
From: John Lightsey <jd@cpanel.net>
8e746e
Date: Wed, 20 Nov 2019 20:02:45 -0600
8e746e
Subject: [PATCH v528 1/3] regcomp.c: Prevent integer overflow from nested
8e746e
 regex quantifiers.
8e746e
8e746e
(CVE-2020-10543) On 32bit systems the size calculations for nested regular
8e746e
expression quantifiers could overflow causing heap memory corruption.
8e746e
8e746e
Fixes: Perl/perl5-security#125
8e746e
---
8e746e
 regcomp.c | 6 ++++++
8e746e
 1 file changed, 6 insertions(+)
8e746e
8e746e
diff --git a/regcomp.c b/regcomp.c
8e746e
index e1da15a77c..dd18add1db 100644
8e746e
--- a/regcomp.c
8e746e
+++ b/regcomp.c
8e746e
@@ -5102,6 +5139,12 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode **scanp,
8e746e
 		    (void)ReREFCNT_inc(RExC_rx_sv);
8e746e
 		}
8e746e
 
8e746e
+                if ( ( minnext > 0 && mincount >= SSize_t_MAX / minnext )
8e746e
+                    || min >= SSize_t_MAX - minnext * mincount )
8e746e
+                {
8e746e
+                    FAIL("Regexp out of space");
8e746e
+                }
8e746e
+
8e746e
 		min += minnext * mincount;
8e746e
 		is_inf_internal |= deltanext == SSize_t_MAX
8e746e
                          || (maxcount == REG_INFTY && minnext + deltanext > 0);
8e746e
-- 
8e746e
2.20.1
8e746e