diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-12-10 16:58:59 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-12-10 16:58:59 +0000 |
commit | 4d5a265529bcdf5115cbb9fcc5688bf32232eb32 (patch) | |
tree | 12549e244ba19cadf6660ad04879e151877cc6a1 /src/libserver/re_cache.c | |
parent | 8e57fc2c1d7b3d5f7a9839f140e3502ee69e3d61 (diff) | |
download | rspamd-4d5a265529bcdf5115cbb9fcc5688bf32232eb32.tar.gz rspamd-4d5a265529bcdf5115cbb9fcc5688bf32232eb32.zip |
Fix maxhits for pcre
Diffstat (limited to 'src/libserver/re_cache.c')
-rw-r--r-- | src/libserver/re_cache.c | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/src/libserver/re_cache.c b/src/libserver/re_cache.c index 18c463db5..11ad7ba0a 100644 --- a/src/libserver/re_cache.c +++ b/src/libserver/re_cache.c @@ -428,6 +428,7 @@ rspamd_re_cache_process_pcre (struct rspamd_re_runtime *rt, guint r = 0; const gchar *start = NULL, *end = NULL; guint max_hits = rspamd_regexp_get_maxhits (re); + guint64 id = rspamd_regexp_get_cache_id (re); if (len == 0) { len = strlen (in); @@ -437,26 +438,33 @@ rspamd_re_cache_process_pcre (struct rspamd_re_runtime *rt, len = rt->cache->max_re_data; } - while (rspamd_regexp_search (re, - in, - len, - &start, - &end, - is_raw, - NULL)) { - r++; - - if (max_hits > 0 && r > max_hits) { - break; + r = rt->results[id]; + + if (max_hits == 0 || r < max_hits) { + while (rspamd_regexp_search (re, + in, + len, + &start, + &end, + is_raw, + NULL)) { + r++; + + if (max_hits > 0 && r >= max_hits) { + break; + } } - } - rt->stat.regexp_checked ++; - rt->stat.bytes_scanned_pcre += len; - rt->stat.bytes_scanned += len; + rt->stat.regexp_checked++; + rt->stat.bytes_scanned_pcre += len; + rt->stat.bytes_scanned += len; - if (r > 0) { - rt->stat.regexp_matched += r; + if (r > 0) { + rt->stat.regexp_matched += r; + } + } + else { + r = 0; } return r; |