From: Vsevolod Stakhov Date: Thu, 25 Dec 2025 11:24:13 +0000 (+0000) Subject: [Fix] Add null checks for task in Redis stat callbacks X-Git-Tag: 3.14.3~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd75b83d31b93837b0cfeddc096099085a05e17d;p=thirdparty%2Frspamd.git [Fix] Add null checks for task in Redis stat callbacks Prevent crash when task becomes invalid during async Redis callbacks by checking lua_check_task return value. --- diff --git a/src/libstat/backends/redis_backend.cxx b/src/libstat/backends/redis_backend.cxx index 37ce6e9da7..2acaf9db0d 100644 --- a/src/libstat/backends/redis_backend.cxx +++ b/src/libstat/backends/redis_backend.cxx @@ -904,10 +904,15 @@ rspamd_redis_classified(lua_State *L) { const auto *cookie = lua_tostring(L, lua_upvalueindex(1)); auto *task = lua_check_task(L, 1); + + if (task == nullptr) { + return 0; + } + auto *rt = REDIS_RUNTIME(rspamd_mempool_get_variable(task->task_pool, cookie)); if (rt == nullptr) { - msg_err_task("internal error: cannot find runtime for cookie %s", cookie); + msg_err_task("cannot find runtime for cookie %s", cookie); return 0; } @@ -1339,10 +1344,15 @@ rspamd_redis_learned(lua_State *L) { const auto *cookie = lua_tostring(L, lua_upvalueindex(1)); auto *task = lua_check_task(L, 1); + + if (task == nullptr) { + return 0; + } + auto *rt = REDIS_RUNTIME(rspamd_mempool_get_variable(task->task_pool, cookie)); if (rt == nullptr) { - msg_err_task("internal error: cannot find runtime for cookie %s", cookie); + msg_err_task("cannot find runtime for cookie %s", cookie); return 0; } diff --git a/src/libstat/learn_cache/redis_cache.cxx b/src/libstat/learn_cache/redis_cache.cxx index afefeadcda..484a21cce3 100644 --- a/src/libstat/learn_cache/redis_cache.cxx +++ b/src/libstat/learn_cache/redis_cache.cxx @@ -183,6 +183,11 @@ static int rspamd_stat_cache_checked(lua_State *L) { auto *task = lua_check_task(L, 1); + + if (task == nullptr) { + return 0; + } + auto res = lua_toboolean(L, 2); if (res) { diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c index bb0af61752..8cf0448f5e 100644 --- a/src/plugins/dkim_check.c +++ b/src/plugins/dkim_check.c @@ -758,6 +758,10 @@ lua_dkim_sign_handler(lua_State *L) gboolean no_cache = FALSE, strict_pubkey_check = FALSE; struct dkim_ctx *dkim_module_ctx; + if (task == NULL) { + return luaL_error(L, "invalid task"); + } + luaL_argcheck(L, lua_type(L, 2) == LUA_TTABLE, 2, "'table' expected"); /* * Get the following elements: @@ -956,6 +960,10 @@ lua_dkim_load_sign_key_handler(lua_State *L) struct dkim_ctx *dkim_module_ctx; rspamd_dkim_sign_key_t **pkey; + if (task == NULL) { + return luaL_error(L, "invalid task"); + } + luaL_argcheck(L, lua_type(L, 2) == LUA_TTABLE, 2, "'table' expected"); if (!rspamd_lua_parse_table_arguments(L, 2, &err, @@ -1035,6 +1043,10 @@ lua_dkim_sign_digest_handler(lua_State *L) const unsigned char *digest_data; char *sig_b64 = NULL; + if (task == NULL) { + return luaL_error(L, "invalid task"); + } + luaL_argcheck(L, lua_type(L, 2) == LUA_TTABLE, 2, "'table' expected"); /* Get sign_key from table */