diff --git a/ChangeLog b/ChangeLog index e4bee24..09dfe2e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,8 @@ vNEXT: Fix proxyprotocol target field (Thanks to Github user 404-Not-Found) + Fix memory leak in regex probe. + v2.2.4: Fix CVE-2025-46806 for "Misaligned Memory Accesses in `is_openvpn_protocol()`" diff --git a/probe.c b/probe.c index 37f9bb6..c6a05d5 100644 --- a/probe.c +++ b/probe.c @@ -21,10 +21,6 @@ #define _GNU_SOURCE #include -#ifdef ENABLE_REGEX -#define PCRE2_CODE_UNIT_WIDTH 8 -#include -#endif #include #include #include "probe.h" @@ -429,16 +425,18 @@ static int is_msrdp_protocol(const char *p, ssize_t len, struct sslhcfg_protocol return packet_len == len; } +#ifdef ENABLE_REGEX +pcre2_match_data* probe_regex_matches; +#endif + static int regex_probe(const char *p, ssize_t len, struct sslhcfg_protocols_item* proto) { #ifdef ENABLE_REGEX pcre2_code**probe = (pcre2_code**)proto->data; - pcre2_match_data* matches; - matches = pcre2_match_data_create(1, NULL); for (; *probe; probe++) { - int res = pcre2_match(*probe, (PCRE2_SPTR8)p, len, 0, 0, matches, NULL); + int res = pcre2_match(*probe, (PCRE2_SPTR8)p, len, 0, 0, probe_regex_matches, NULL); if (res >= 0) return 1; } diff --git a/probe.h b/probe.h index d0b768b..925ca5c 100644 --- a/probe.h +++ b/probe.h @@ -66,4 +66,11 @@ struct sslhcfg_protocols_item* timeout_protocol(void); void hexdump(msg_info, const char*, unsigned int); +#ifdef ENABLE_REGEX +#define PCRE2_CODE_UNIT_WIDTH 8 +#include +extern pcre2_match_data* probe_regex_matches; +#endif + + #endif diff --git a/sslh-main.c b/sslh-main.c index ba3de13..99aa0f4 100644 --- a/sslh-main.c +++ b/sslh-main.c @@ -130,6 +130,7 @@ static void setup_regex_probe(struct sslhcfg_protocols_item *p) exit(1); } } + probe_regex_matches = pcre2_match_data_create(1, NULL); } #else {