File nmap-7.70-CVE-2018-15173_pcre_limits.patch of Package nmap.12600
From 6d8bb6df229f7acf768bcebfe14cdc8c3dbbe92b Mon Sep 17 00:00:00 2001
From: dmiller <dmiller@e0a8ed71-7df4-0310-8962-fdc924857419>
Date: Wed, 8 Aug 2018 16:36:21 +0000
Subject: [PATCH] Set limits on PCRE matches to avoid issues like #1147
CVE-2018-15173
---
service_scan.cc | 15 +++++++++++++++
1 file changed, 15 insertions(+)
Index: nmap-7.70/service_scan.cc
===================================================================
--- nmap-7.70.orig/service_scan.cc
+++ nmap-7.70/service_scan.cc
@@ -485,10 +485,28 @@ void ServiceProbeMatch::InitMatch(const
fatal("%s: illegal regexp on line %d of nmap-service-probes (at regexp offset %d): %s\n", __func__, lineno, pcre_erroffset, pcre_errptr);
// Now study the regexp for greater efficiency
- regex_extra = pcre_study(regex_compiled, 0, &pcre_errptr);
+ regex_extra = pcre_study(regex_compiled, 0
+#ifdef PCRE_STUDY_EXTRA_NEEDED
+ | PCRE_STUDY_EXTRA_NEEDED
+#endif
+ , &pcre_errptr);
if (pcre_errptr != NULL)
fatal("%s: failed to pcre_study regexp on line %d of nmap-service-probes: %s\n", __func__, lineno, pcre_errptr);
+ if (!regex_extra) {
+ regex_extra = (pcre_extra *) pcre_malloc(sizeof(pcre_extra));
+ memset(regex_extra, 0, sizeof(pcre_extra));
+ }
+
+ // Set some limits to avoid evil match cases.
+ // These are flexible; if they cause problems, increase them.
+#ifdef PCRE_ERROR_MATCHLIMIT
+ regex_extra->match_limit = 100000; // 100K
+#endif
+#ifdef PCRE_ERROR_RECURSIONLIMIT
+ regex_extra->match_limit_recursion = 10000; // 10K
+#endif
+
free(modestr);
free(flags);
@@ -569,6 +587,12 @@ const struct MatchDetails *ServiceProbeM
error("Warning: Hit PCRE_ERROR_MATCHLIMIT when probing for service %s with the regex '%s'", servicename, matchstr);
} else
#endif // PCRE_ERROR_MATCHLIMIT
+#ifdef PCRE_ERROR_RECURSIONLIMIT
+ if (rc == PCRE_ERROR_RECURSIONLIMIT) {
+ if (o.debugging || o.verbose > 1)
+ error("Warning: Hit PCRE_ERROR_RECURSIONLIMIT when probing for service %s with the regex '%s'", servicename, matchstr);
+ } else
+#endif // PCRE_ERROR_MATCHLIMIT
if (rc != PCRE_ERROR_NOMATCH) {
fatal("Unexpected PCRE error (%d) when probing for service %s with the regex '%s'", rc, servicename, matchstr);
}