aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil/regexp.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-10-09 13:25:08 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-10-09 13:25:08 +0100
commit9791674f7f656703af74e45949f445c7b30c90d2 (patch)
tree7212fedf99fb2aed0a25dffae066357479acb675 /src/libutil/regexp.c
parent4a3a6e52ce533d2697482c0ee0287f7a8be898d6 (diff)
downloadrspamd-9791674f7f656703af74e45949f445c7b30c90d2.tar.gz
rspamd-9791674f7f656703af74e45949f445c7b30c90d2.zip
[Fix] Set sanity limits for pcre2
Diffstat (limited to 'src/libutil/regexp.c')
-rw-r--r--src/libutil/regexp.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/libutil/regexp.c b/src/libutil/regexp.c
index 4ce9c4218..b7aae457e 100644
--- a/src/libutil/regexp.c
+++ b/src/libutil/regexp.c
@@ -158,13 +158,21 @@ rspamd_regexp_post_process (rspamd_regexp_t *r)
}
#if defined(WITH_PCRE2)
gsize jsz;
+ static const guint max_recursion_depth = 100000, max_backtrack = 1000000;
+
guint jit_flags = can_jit ? PCRE2_JIT_COMPLETE : 0;
- /* Create match context */
+ /* Create match context */
r->mcontext = pcre2_match_context_create (NULL);
+ g_assert (r->mcontext != NULL);
+ pcre2_set_depth_limit (r->mcontext, max_recursion_depth);
+ pcre2_set_match_limit (r->mcontext, max_backtrack);
if (r->re != r->raw_re) {
r->raw_mcontext = pcre2_match_context_create (NULL);
+ g_assert (r->raw_mcontext != NULL);
+ pcre2_set_depth_limit (r->raw_mcontext, max_recursion_depth);
+ pcre2_set_match_limit (r->raw_mcontext, max_backtrack);
}
else {
r->raw_mcontext = r->mcontext;