25c98b9
From f0bb9e8baf3157e0a84f484f194984295b2db23a Mon Sep 17 00:00:00 2001
25c98b9
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
25c98b9
Date: Mon, 19 Oct 2020 16:15:14 +0200
25c98b9
Subject: [PATCH] Inicialize name table memory region
25c98b9
MIME-Version: 1.0
25c98b9
Content-Type: text/plain; charset=UTF-8
25c98b9
Content-Transfer-Encoding: 8bit
25c98b9
25c98b9
Name table entry values are accessed past their ends in add_name()
25c98b9
when comparing the values. Also a size of the entries could grow
25c98b9
later. It's safer to initialize just after the allocation than to hunt
25c98b9
the gaps later.
25c98b9
25c98b9
Reproducer:
25c98b9
25c98b9
pcre_compile2("(?<f>)(?<fir>)", PCRE_NO_AUTO_CAPTURE | PCRE_CASELESS, &ec, &eb, &eo, NULL);
25c98b9
25c98b9
built with clang++ -fsanitize=memory -fsanitize=fuzzer-no-link.
25c98b9
25c98b9
https://bugs.exim.org/show_bug.cgi?id=2661
25c98b9
Signed-off-by: Petr Písař <ppisar@redhat.com>
25c98b9
---
25c98b9
 pcre_compile.c | 5 +++++
25c98b9
 1 file changed, 5 insertions(+)
25c98b9
25c98b9
diff --git a/pcre_compile.c b/pcre_compile.c
25c98b9
index 3be0fbf..75309e0 100644
25c98b9
--- a/pcre_compile.c
25c98b9
+++ b/pcre_compile.c
25c98b9
@@ -9423,6 +9423,11 @@ if (re == NULL)
25c98b9
   goto PCRE_EARLY_ERROR_RETURN;
25c98b9
   }
25c98b9
 
25c98b9
+/* Initialize the memory. Name table entry values are accessed past their ends
25c98b9
+ * (e.g. in add_name()) when comparing the values. Also a size of the entry can
25c98b9
+ * grow later. It's safer to initialize here than to hunt the gaps later. */
25c98b9
+memset(re, 0, size);
25c98b9
+
25c98b9
 /* Put in the magic number, and save the sizes, initial options, internal
25c98b9
 flags, and character table pointer. NULL is used for the default character
25c98b9
 tables. The nullpad field is at the end; it's there to help in the case when a
25c98b9
-- 
25c98b9
2.25.4
25c98b9