]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Add null checks for task in Redis stat callbacks
authorVsevolod Stakhov <vsevolod@rspamd.com>
Thu, 25 Dec 2025 11:24:13 +0000 (11:24 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Thu, 25 Dec 2025 11:24:13 +0000 (11:24 +0000)
Prevent crash when task becomes invalid during async Redis
callbacks by checking lua_check_task return value.

src/libstat/backends/redis_backend.cxx
src/libstat/learn_cache/redis_cache.cxx
src/plugins/dkim_check.c

index 37ce6e9da7a0b102387e70e64e39fc7f2cf7dba0..2acaf9db0d2f3cd25eb4295477173d2841226de9 100644 (file)
@@ -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;
        }
index afefeadcdab3604630d097993cc3db9c6c13940a..484a21cce3ba2922998705d0ae0fc1b74a47407c 100644 (file)
@@ -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) {
index bb0af617520e08ad34dcb70ce314ba76e45d796e..8cf0448f5e4ffdf318a2b59ab68addccba9e7604 100644 (file)
@@ -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 */