X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/d8fbda7da9eb20f98b89f625e8a77eacc443757d..89318c714454e11217505d2163d807d5d827f50a:/src/src/regex_cache.c diff --git a/src/src/regex_cache.c b/src/src/regex_cache.c index 6ac134cd8..63cddce1d 100644 --- a/src/src/regex_cache.c +++ b/src/src/regex_cache.c @@ -39,6 +39,8 @@ typedef struct re_req { static tree_node * regex_cache = NULL; static tree_node * regex_caseless_cache = NULL; +#define REGEX_CACHESIZE_LIMIT 1000 + /******************************************************************************/ static void @@ -236,9 +238,14 @@ regex_at_daemon(const uschar * reqbuf) { const re_req * req = (const re_req *)reqbuf; uschar * errstr; -const pcre2_code * cre = regex_compile(req->re, - req->caseless ? MCS_CASELESS | MCS_CACHEABLE : MCS_CACHEABLE, - &errstr, pcre_gen_cmp_ctx); +const pcre2_code * cre; + +if (regex_cachesize >= REGEX_CACHESIZE_LIMIT) + errstr = US"regex cache size limit reached"; +else if ((cre = regex_compile(req->re, + req->caseless ? MCS_CASELESS | MCS_CACHEABLE : MCS_CACHEABLE, + &errstr, pcre_gen_cmp_ctx))) + regex_cachesize++; DEBUG(D_any) if (!cre) debug_printf("%s\n", errstr); return;