Browse Source

Honor pcre flags in hyperscan expressions

tags/1.1.0
Vsevolod Stakhov 8 years ago
parent
commit
86998b2677
1 changed files with 16 additions and 7 deletions
  1. 16
    7
      src/libserver/re_cache.c

+ 16
- 7
src/libserver/re_cache.c View File

#include "hs.h" #include "hs.h"
#include "unix-std.h" #include "unix-std.h"
#include <signal.h> #include <signal.h>
#include <pcre.h>


#ifdef HAVE_SYS_WAIT_H #ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h> #include <sys/wait.h>
#ifdef WITH_HYPERSCAN #ifdef WITH_HYPERSCAN
static gboolean static gboolean
rspamd_re_cache_is_finite (struct rspamd_re_cache *cache, rspamd_re_cache_is_finite (struct rspamd_re_cache *cache,
rspamd_regexp_t *re)
rspamd_regexp_t *re, gint flags)
{ {
pid_t cld; pid_t cld;
gint status; gint status;
if (cld == 0) { if (cld == 0) {
/* Try to compile pattern */ /* Try to compile pattern */
if (hs_compile (rspamd_regexp_get_pattern (re), if (hs_compile (rspamd_regexp_get_pattern (re),
HS_FLAG_ALLOWEMPTY | HS_FLAG_PREFILTER,
flags | HS_FLAG_PREFILTER,
HS_MODE_BLOCK, HS_MODE_BLOCK,
&cache->plt, &cache->plt,
&test_db, &test_db,
struct rspamd_re_class *re_class; struct rspamd_re_class *re_class;
gchar path[PATH_MAX]; gchar path[PATH_MAX];
hs_database_t *test_db; hs_database_t *test_db;
gint fd, i, n, *hs_ids = NULL;
gint fd, i, n, *hs_ids = NULL, pcre_flags;
guint64 crc; guint64 crc;
rspamd_regexp_t *re; rspamd_regexp_t *re;
hs_compile_error_t *hs_errors; hs_compile_error_t *hs_errors;
while (g_hash_table_iter_next (&cit, &k, &v)) { while (g_hash_table_iter_next (&cit, &k, &v)) {
re = v; re = v;


hs_flags[i] = 0;
pcre_flags = rspamd_regexp_get_pcre_flags (re);
if (pcre_flags & PCRE_UTF8) {
hs_flags[i] |= HS_FLAG_UTF8;
}
if (pcre_flags & PCRE_CASELESS) {
hs_flags[i] |= HS_FLAG_CASELESS;
}

if (hs_compile (rspamd_regexp_get_pattern (re), if (hs_compile (rspamd_regexp_get_pattern (re),
HS_FLAG_ALLOWEMPTY,
hs_flags[i],
HS_MODE_BLOCK, HS_MODE_BLOCK,
&cache->plt, &cache->plt,
&test_db, &test_db,
/* The approximation operation might take a significant /* The approximation operation might take a significant
* amount of time, so we need to check if it's finite * amount of time, so we need to check if it's finite
*/ */
if (rspamd_re_cache_is_finite (cache, re)) {
hs_flags[i] = HS_FLAG_ALLOWEMPTY | HS_FLAG_PREFILTER;
if (rspamd_re_cache_is_finite (cache, re, hs_flags[i])) {
hs_flags[i] |= HS_FLAG_PREFILTER;
hs_ids[i] = rspamd_regexp_get_cache_id (re); hs_ids[i] = rspamd_regexp_get_cache_id (re);
hs_pats[i] = rspamd_regexp_get_pattern (re); hs_pats[i] = rspamd_regexp_get_pattern (re);
i++; i++;
} }
} }
else { else {
hs_flags[i] = HS_FLAG_ALLOWEMPTY;
hs_ids[i] = rspamd_regexp_get_cache_id (re); hs_ids[i] = rspamd_regexp_get_cache_id (re);
hs_pats[i] = rspamd_regexp_get_pattern (re); hs_pats[i] = rspamd_regexp_get_pattern (re);
i ++; i ++;

Loading…
Cancel
Save