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