diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-10-04 13:38:10 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-10-04 13:38:10 +0100 |
commit | 6c76c1728c81e25be854e36cd9def1d689536b27 (patch) | |
tree | 6c31c5e132be7169704b50670ef7810703124819 /src | |
parent | 39dfdab80d11c6bc7b10f37d819414358d5249f9 (diff) | |
download | rspamd-6c76c1728c81e25be854e36cd9def1d689536b27.tar.gz rspamd-6c76c1728c81e25be854e36cd9def1d689536b27.zip |
[Minor] Strictly check worker context magic
Diffstat (limited to 'src')
-rw-r--r-- | src/controller.c | 1 | ||||
-rw-r--r-- | src/fuzzy_storage.c | 1 | ||||
-rw-r--r-- | src/hs_helper.c | 1 | ||||
-rw-r--r-- | src/libserver/worker_util.c | 8 | ||||
-rw-r--r-- | src/libserver/worker_util.h | 8 | ||||
-rw-r--r-- | src/rspamd_proxy.c | 1 | ||||
-rw-r--r-- | src/worker.c | 2 |
7 files changed, 21 insertions, 1 deletions
diff --git a/src/controller.c b/src/controller.c index 27c6d18cc..332737724 100644 --- a/src/controller.c +++ b/src/controller.c @@ -3701,6 +3701,7 @@ start_controller_worker (struct rspamd_worker *worker) const ev_tstamp save_stats_interval = 60; /* 1 minute */ gpointer m; + g_assert (rspamd_worker_check_context (worker->ctx, rspamd_controller_ctx_magic)); ctx->event_loop = rspamd_prepare_worker (worker, "controller", rspamd_controller_accept_socket); diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c index ef2afac4b..d0d69c83c 100644 --- a/src/fuzzy_storage.c +++ b/src/fuzzy_storage.c @@ -1895,6 +1895,7 @@ start_fuzzy (struct rspamd_worker *worker) struct rspamd_srv_command srv_cmd; struct rspamd_config *cfg = worker->srv->cfg; + g_assert (rspamd_worker_check_context (worker->ctx, rspamd_fuzzy_storage_magic)); ctx->event_loop = rspamd_prepare_worker (worker, "fuzzy", NULL); diff --git a/src/hs_helper.c b/src/hs_helper.c index 3cdc2a439..a20e176f6 100644 --- a/src/hs_helper.c +++ b/src/hs_helper.c @@ -303,6 +303,7 @@ start_hs_helper (struct rspamd_worker *worker) struct hs_helper_ctx *ctx = worker->ctx; double tim; + g_assert (rspamd_worker_check_context (worker->ctx, rspamd_hs_helper_magic)); ctx->cfg = worker->srv->cfg; if (ctx->hs_dir == NULL) { diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c index 4779fd57a..eff39a8b0 100644 --- a/src/libserver/worker_util.c +++ b/src/libserver/worker_util.c @@ -1472,4 +1472,12 @@ rspamd_worker_hyperscan_ready (struct rspamd_main *rspamd_main, return TRUE; } + +gboolean +rspamd_worker_check_context (gpointer ctx, guint64 magic) +{ + struct rspamd_abstract_worker_ctx *actx = (struct rspamd_abstract_worker_ctx*)ctx; + + return actx->magic == magic; +} #endif
\ No newline at end of file diff --git a/src/libserver/worker_util.h b/src/libserver/worker_util.h index d0966e009..6fbda0b4a 100644 --- a/src/libserver/worker_util.h +++ b/src/libserver/worker_util.h @@ -58,6 +58,14 @@ rspamd_prepare_worker (struct rspamd_worker *worker, const char *name, rspamd_accept_handler hdl); /** + * Should be used to validate context for a worker as in assert like invocation + * @param ctx + * @param magic + * @return + */ +gboolean rspamd_worker_check_context (gpointer ctx, guint64 magic); + +/** * Set special signal handler for a worker */ void rspamd_worker_set_signal_handler (int signo, diff --git a/src/rspamd_proxy.c b/src/rspamd_proxy.c index be3395273..dbf905609 100644 --- a/src/rspamd_proxy.c +++ b/src/rspamd_proxy.c @@ -2216,6 +2216,7 @@ start_rspamd_proxy (struct rspamd_worker *worker) { struct rspamd_proxy_ctx *ctx = worker->ctx; + g_assert (rspamd_worker_check_context (worker->ctx, rspamd_rspamd_proxy_magic)); ctx->cfg = worker->srv->cfg; ctx->event_loop = rspamd_prepare_worker (worker, "rspamd_proxy", proxy_accept_socket); diff --git a/src/worker.c b/src/worker.c index 349a0ea92..04447feea 100644 --- a/src/worker.c +++ b/src/worker.c @@ -525,7 +525,6 @@ init_worker (struct rspamd_config *cfg) GQuark type; type = g_quark_try_string ("normal"); - ctx = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_worker_ctx)); @@ -645,6 +644,7 @@ start_worker (struct rspamd_worker *worker) { struct rspamd_worker_ctx *ctx = worker->ctx; + g_assert (rspamd_worker_check_context (worker->ctx, rspamd_worker_magic)); ctx->cfg = worker->srv->cfg; ctx->event_loop = rspamd_prepare_worker (worker, "normal", accept_socket); rspamd_symcache_start_refresh (worker->srv->cfg->cache, ctx->event_loop, |