]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] lua_maps: handle empty table as static empty map
authorAlexander Moisseev <moiseev@mezonplus.ru>
Sun, 26 Apr 2026 06:52:22 +0000 (09:52 +0300)
committerAlexander Moisseev <moiseev@mezonplus.ru>
Sun, 26 Apr 2026 07:28:46 +0000 (10:28 +0300)
When map_add_from_ucl receives an empty Lua table, it fell through
to the C map infrastructure, which logged a spurious error-level
message with no map name. Return a lightweight empty map object
directly in Lua, cache it for consistency with other code paths,
and log a warning since an empty table is likely a misconfiguration.

lualib/lua_maps.lua

index 80319df41b3e6615af3bf94b4ee5f7cce7d67d6f..c14cc940dbbe7fafcb803891afd53eb97f56bcda 100644 (file)
@@ -391,6 +391,19 @@ local function rspamd_map_add_from_ucl(opt, mtype, description, callback)
       return maps_cache[cache_key]
     end
 
+    if not next(opt) then
+      -- Empty table: return a static empty map without involving C map infrastructure,
+      -- avoiding a spurious error log when an intentionally empty default is used.
+      rspamd_logger.warnx(rspamd_config, 'empty static map definition for: %s', description)
+      ret.get_key = function(_, _) return nil end
+      ret.foreach = function(_, _) return true end
+      ret.on_load = function(_, cb)
+        rspamd_config:add_on_load(function(_, _, _) cb() end)
+      end
+      maps_cache[cache_key] = ret
+      return ret
+    end
+
     if opt[1] then
       local function check_plain_map(line)
         return lua_util.str_startswith(line, 'http')