]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Set sanity limits for pcre2
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 9 Oct 2019 12:25:08 +0000 (13:25 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 9 Oct 2019 12:25:08 +0000 (13:25 +0100)
src/libutil/regexp.c

index 4ce9c4218a4089e7ced77e6b1a81df0fc23d9869..b7aae457e7f8c06d674527b009189f774c980365 100644 (file)
@@ -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;