diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-05-13 13:00:52 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-05-13 13:00:52 +0100 |
commit | 5d5dbfad17e29ecf8590380c941bf5f5026cd577 (patch) | |
tree | 7886f54f120e36cabf3ff498c169d97c7c80c7b3 | |
parent | 78c29d057daaadc2eb56ef597c0f3dc3c4f31760 (diff) | |
download | rspamd-5d5dbfad17e29ecf8590380c941bf5f5026cd577.tar.gz rspamd-5d5dbfad17e29ecf8590380c941bf5f5026cd577.zip |
Fix another issues with raw/utf regexps.
-rw-r--r-- | src/libutil/regexp.c | 77 |
1 files changed, 44 insertions, 33 deletions
diff --git a/src/libutil/regexp.c b/src/libutil/regexp.c index deaca80a5..02ece3350 100644 --- a/src/libutil/regexp.c +++ b/src/libutil/regexp.c @@ -87,6 +87,19 @@ static void rspamd_regexp_dtor (rspamd_regexp_t *re) { if (re) { + if (re->raw_re && re->raw_re != re->re) { + pcre_free (re->raw_re); +#ifdef HAVE_PCRE_JIT + if (re->raw_extra) { + pcre_free_study (re->raw_extra); + } + if (re->raw_jstack) { + pcre_jit_stack_free (re->raw_jstack); + } +#else + pcre_free (re->raw_extra); +#endif + } if (re->re) { pcre_free (re->re); #ifdef HAVE_PCRE_JIT @@ -100,19 +113,6 @@ rspamd_regexp_dtor (rspamd_regexp_t *re) pcre_free (re->extra); #endif } - if (re->raw_re) { - pcre_free (re->raw_re); -#ifdef HAVE_PCRE_JIT - if (re->raw_extra) { - pcre_free_study (re->raw_extra); - } - if (re->raw_jstack) { - pcre_jit_stack_free (re->raw_jstack); - } -#else - pcre_free (re->raw_extra); -#endif - } if (re->pattern) { g_free (re->pattern); @@ -274,7 +274,7 @@ fin: PCRE_INFO_JIT, &jit); if (n != 0 || jit != 1) { - msg_info ("jit compilation of %s is not supported", pattern); + msg_debug ("jit compilation of %s is not supported", pattern); res->jstack = NULL; } else { @@ -289,31 +289,42 @@ fin: pattern, err_str); } } + if (res->raw_re) { - res->raw_extra = pcre_study (res->raw_re, study_flags, &err_str); - if (res->raw_extra != NULL) { + if (res->raw_re != res->re) { + res->raw_extra = pcre_study (res->raw_re, study_flags, &err_str); + if (res->raw_extra != NULL) { #ifdef HAVE_PCRE_JIT - gint jit, n; - - if (can_jit) { - jit = 0; - n = pcre_fullinfo (res->re, res->extra, - PCRE_INFO_JIT, &jit); - - if (n != 0 || jit != 1) { - msg_info ("jit compilation of %s is not supported", pattern); - res->jstack = NULL; - } - else { - res->jstack = pcre_jit_stack_alloc (32 * 1024, 512 * 1024); - pcre_assign_jit_stack (res->extra, NULL, res->jstack); + gint jit, n; + + if (can_jit) { + jit = 0; + n = pcre_fullinfo (res->raw_re, res->raw_extra, + PCRE_INFO_JIT, &jit); + + if (n != 0 || jit != 1) { + msg_debug ("jit compilation of %s is not supported", + pattern); + res->raw_jstack = NULL; + } + else { + res->raw_jstack = pcre_jit_stack_alloc (32 * 1024, + 512 * 1024); + pcre_assign_jit_stack (res->raw_extra, NULL, + res->raw_jstack); + } } - } #endif + } + else { + msg_warn ("cannot optimize raw regexp pattern: '%s': %s", + pattern, err_str); + } } else { - msg_warn ("cannot optimize raw regexp pattern: '%s': %s", - pattern, err_str); + /* Just alias pointers */ + res->raw_extra = res->extra; + res->raw_jstack = res->jstack; } } } |