From: Vsevolod Stakhov Date: Mon, 27 Jul 2015 14:32:00 +0000 (+0100) Subject: Fix issues with compatibility tokenization. X-Git-Tag: 1.0.0~277 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=52b516b6aa93fef63979404bd581abf4ec587feb;p=thirdparty%2Frspamd.git Fix issues with compatibility tokenization. --- diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c index 3ec579049a..141b2dfd5a 100644 --- a/src/libstat/stat_process.c +++ b/src/libstat/stat_process.c @@ -157,6 +157,7 @@ rspamd_stat_get_tokenizer_runtime (struct rspamd_tokenizer_config *cf, tok = rspamd_mempool_alloc (task->task_pool, sizeof (*tok)); tok->tokenizer = rspamd_stat_get_tokenizer (name); + tok->tkcf = cf; if (tok->tokenizer == NULL) { return NULL; @@ -168,7 +169,6 @@ rspamd_stat_get_tokenizer_runtime (struct rspamd_tokenizer_config *cf, tok->config = conf; tok->conf_len = conf_len; - tok->tkcf = cf; tok->tokens = g_tree_new (token_node_compare_func); rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t)g_tree_destroy, tok->tokens); @@ -295,13 +295,17 @@ rspamd_stat_preprocess (struct rspamd_stat_ctx *st_ctx, } cl_runtime->clcf = clcf; + bk = rspamd_stat_get_backend (clcf->backend); if (bk == NULL) { - msg_warn ("backend of type %s is not defined", clcf->backend); - cur = g_list_next (cur); - continue; + g_set_error (err, rspamd_stat_quark(), 500, + "backend %s is not defined", clcf->backend); + g_list_free (cl_runtimes); + return NULL; } + cl_runtime->backend = bk; + curst = st_list; while (curst != NULL) { stcf = (struct rspamd_statfile_config *)curst->data; @@ -348,15 +352,14 @@ rspamd_stat_preprocess (struct rspamd_stat_ctx *st_ctx, return NULL; } } - else { - if (!cl_runtime->tok->tokenizer->compatible_config ( - cl_runtime->tok, tok_config, conf_len)) { - g_set_error (err, rspamd_stat_quark(), 500, - "incompatible tokenizer for statfile %s", stcf->symbol); - g_list_free (cl_runtimes); - return NULL; - } + if (!cl_runtime->tok->tokenizer->compatible_config ( + cl_runtime->tok, tok_config, conf_len)) { + g_set_error (err, rspamd_stat_quark(), 500, + "incompatible tokenizer for statfile %s", stcf->symbol); + g_list_free (cl_runtimes); + + return NULL; } st_runtime = rspamd_mempool_alloc0 (task->task_pool, diff --git a/src/libstat/tokenizers/osb.c b/src/libstat/tokenizers/osb.c index 40dec0d820..bbb2656c23 100644 --- a/src/libstat/tokenizers/osb.c +++ b/src/libstat/tokenizers/osb.c @@ -347,8 +347,16 @@ rspamd_tokenizer_osb_load_config (rspamd_mempool_t *pool, { struct rspamd_osb_tokenizer_config *osb_cf; - if (ptr == NULL) { + if (ptr == NULL || len == 0) { osb_cf = rspamd_tokenizer_osb_config_from_ucl (pool, rt->tkcf->opts); + + if (osb_cf->ht != RSPAMD_OSB_HASH_COMPAT) { + /* Trying to load incompatible configuration */ + msg_err ("cannot load tokenizer configuration from a legacy statfile," + " maybe you have forgotten to set 'compat' option in the " + "tokenizer configuration"); + return FALSE; + } } else { g_assert (len == sizeof (*osb_cf));