X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fsrc%2Fregex_cache.c;h=a9b482174a38e8494fb531ea3aeef2ad5ae40b31;hb=4f7a93c27e3d43b44c42d3fc503f03b9b42ca622;hp=6ac134cd8d8debe8c74fce299d0084b8e417759c;hpb=7d5055276a22a91de71104775ade236051cebefc;p=user%2Fhenk%2Fcode%2Fexim.git diff --git a/src/src/regex_cache.c b/src/src/regex_cache.c index 6ac134cd8..a9b482174 100644 --- a/src/src/regex_cache.c +++ b/src/src/regex_cache.c @@ -5,6 +5,7 @@ /* * Copyright (c) The Exim Maintainers 2022 * License: GPL + * SPDX-License-Identifier: GPL-2.0-or-later */ /* Caching layers for compiled REs. There is a local layer in the process, @@ -39,6 +40,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 +239,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;