diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-05-19 13:26:33 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-05-19 13:26:33 +0300 |
commit | e82e00fb191fa357d20e4cf750d455d112f6292c (patch) | |
tree | 8b3fae0d099df00395e76e987f7cf63f7c1faddf /src/libutil | |
parent | 46f96b785505dd0529d2761715e0e29687f5e7d5 (diff) | |
download | rspamd-e82e00fb191fa357d20e4cf750d455d112f6292c.tar.gz rspamd-e82e00fb191fa357d20e4cf750d455d112f6292c.zip |
[Fix] Add sanity checks when compiling regexp maps
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/map.c | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/src/libutil/map.c b/src/libutil/map.c index ae6d59885..1d84e305f 100644 --- a/src/libutil/map.c +++ b/src/libutil/map.c @@ -1955,27 +1955,34 @@ rspamd_re_map_finalize (struct rspamd_regexp_map *re_map) re_map->ids[i] = i; } - if (hs_compile_multi (re_map->patterns, - re_map->flags, - re_map->ids, - re_map->regexps->len, - HS_MODE_BLOCK, - &plt, - &re_map->hs_db, - &err) != HS_SUCCESS) { - - msg_err_map ("cannot create tree of regexp when processing '%s': %s", - re_map->patterns[err->expression], err->message); - re_map->hs_db = NULL; - hs_free_compile_error (err); + if (re_map->regexps->len > 0 && re_map->patterns) { + if (hs_compile_multi (re_map->patterns, + re_map->flags, + re_map->ids, + re_map->regexps->len, + HS_MODE_BLOCK, + &plt, + &re_map->hs_db, + &err) != HS_SUCCESS) { + + msg_err_map ("cannot create tree of regexp when processing '%s': %s", + err->expression >= 0 ? + re_map->patterns[err->expression] : + "unknown regexp", err->message); + re_map->hs_db = NULL; + hs_free_compile_error (err); + + return; + } - return; + if (hs_alloc_scratch (re_map->hs_db, &re_map->hs_scratch) != HS_SUCCESS) { + msg_err_map ("cannot allocate scratch space for hyperscan"); + hs_free_database (re_map->hs_db); + re_map->hs_db = NULL; + } } - - if (hs_alloc_scratch (re_map->hs_db, &re_map->hs_scratch) != HS_SUCCESS) { - msg_err_map ("cannot allocate scratch space for hyperscan"); - hs_free_database (re_map->hs_db); - re_map->hs_db = NULL; + else { + msg_err_map ("regexp map is empty"); } #endif } |