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