]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Lua 5.5 compatibility: do not assign to for-loop variables
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 11 Jul 2026 09:30:34 +0000 (10:30 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 11 Jul 2026 09:30:34 +0000 (10:30 +0100)
Lua 5.5 makes for-loop control variables read-only, so assigning to
them is now a compile-time error. Rebind the value to a local (or pass
it as a closure parameter) in all remaining places; found by
parse-checking the whole tree with luac 5.5.

lualib/lua_aliases.lua
lualib/lua_cfg_transform.lua
lualib/plugins/dmarc.lua
src/plugins/lua/clickhouse.lua
src/plugins/lua/spamassassin.lua
utils/sa_trivial_convert.lua

index a49d8ddc684a5e60aa984c63da2ec49cd58b36ef..15c068d0eb4d2ba23153e97c67be92aadaa76a46 100644 (file)
@@ -332,11 +332,11 @@ function parse_unix_aliases(file_path)
   local current_line = ""
   local line_num = 0
 
-  for line in f:lines() do
+  for raw_line in f:lines() do
     line_num = line_num + 1
 
     -- Strip trailing whitespace
-    line = line:gsub('%s+$', '')
+    local line = raw_line:gsub('%s+$', '')
 
     -- Handle line continuation
     if line:match('\\$') then
@@ -360,8 +360,8 @@ function parse_unix_aliases(file_path)
 
       -- Split targets by comma
       local target_list = {}
-      for target in targets:gmatch('[^,]+') do
-        target = target:gsub('^%s+', ''):gsub('%s+$', '') -- Trim
+      for raw_target in targets:gmatch('[^,]+') do
+        local target = raw_target:gsub('^%s+', ''):gsub('%s+$', '') -- Trim
 
         -- Skip special targets for now (:include:, |program, /file)
         if not target:match('^:include:') and
index f137dea30f3a5ae0bbb68f5a6ebe90fb90cd218f..2c2396425365e86c352b5750c26a1a9e09552966 100644 (file)
@@ -37,7 +37,8 @@ local function surbl_section_convert(cfg, section)
         converted.whitelist = wl
       end
 
-      for k, v in value:pairs() do
+      for opt, v in value:pairs() do
+        local k = opt
         local skip = false
         -- Rename
         if k == 'suffix' then
@@ -103,7 +104,8 @@ local function emails_section_convert(cfg, section)
         converted.whitelist = wl
       end
 
-      for k, v in value:pairs() do
+      for opt, v in value:pairs() do
+        local k = opt
         local skip = false
         -- Rename
         if k == 'dnsbl' then
@@ -180,12 +182,13 @@ local function group_transform(cfg, k, v)
   local symbol_section = v:at('symbol')
   if symbol_section and symbol_section:type() == 'object' then
     for sk, sv in symbol_section:pairs() do
+      local sym_name = sk
       if sv:type() == 'object' and sv:at('name') then
-        sk = sv:at('name'):unwrap()
+        sym_name = sv:at('name'):unwrap()
         sv.name = nil -- Remove field
       end
 
-      new_group.symbols[sk] = sv
+      new_group.symbols[sym_name] = sv
     end
   end
 
index 6e8883f9d1fbce181cfc63c5af2ff45afbcdc252..7d2f6eb2cb3658ddab63478efcd17c9acc9f3f5b 100644 (file)
@@ -254,12 +254,13 @@ local function dmarc_key_value_case(elts)
   end
   local result = {}
   for k, v in pairs(elts) do
-    k = k:lower()
-    if k ~= "v" then
-      v = v:lower()
+    local key = k:lower()
+    local value = v
+    if key ~= "v" then
+      value = v:lower()
     end
 
-    result[k] = v
+    result[key] = value
   end
 
   return result
index a0075b76191eb1e574d156f8e21fb6a0d6d5c4b0..4d85b5c64cedff9e9336bb5bd6c787013ca698a3 100644 (file)
@@ -1796,11 +1796,9 @@ if opts then
       -- Select traverse function depending on what we have
       local iter_func = settings.extra_columns[1] and ipairs or pairs
 
-      for col_name, col_data in iter_func(settings.extra_columns) do
+      for col_key, col_data in iter_func(settings.extra_columns) do
         -- Array based extra columns
-        if col_data.name then
-          col_name = col_data.name
-        end
+        local col_name = col_data.name or col_key
         if not col_data.selector or not col_data.type then
           rspamd_logger.errx(rspamd_config, 'cannot add clickhouse extra row %s: no type or no selector',
               col_name)
index c03481de218352de1feb6d46ea24ec1183b5b361..fcbd4102a5daedb306b8900b17d5439c7851e424 100644 (file)
@@ -711,8 +711,8 @@ local function process_sa_conf(f)
 
   local skip_to_endif = false
   local if_nested = 0
-  for l in f:lines() do
-    (function()
+  for raw_l in f:lines() do
+    (function(l)
       l = lua_util.rspamd_str_trim(l)
       -- Replace bla=~/re/ with bla =~ /re/ (#2372)
       l = l:gsub('([^%s])%s*([=!]~)%s*([^%s])', '%1 %2 %3')
@@ -1076,7 +1076,7 @@ local function process_sa_conf(f)
         end,
             fun.drop_n(1, words))
       end
-    end)()
+    end)(raw_l)
   end
   if valid_rule then
     insert_cur_rule()
index 2ea53bed1edb903d7ef3b1f121dfff05c819d2be..6e7c1f6f3b64e3793c4437aeb1837080db236245 100644 (file)
@@ -152,8 +152,8 @@ local function process_sa_conf(f)
 
   local skip_to_endif = false
   local if_nested = 0
-  for l in f:lines() do
-    (function ()
+  for raw_l in f:lines() do
+    (function (l)
     l = lua_util.rspamd_str_trim(l)
     -- Replace bla=~/re/ with bla =~ /re/ (#2372)
     l = l:gsub('([^%s])%s*([=!]~)%s*([^%s])', '%1 %2 %3')
@@ -342,7 +342,7 @@ local function process_sa_conf(f)
       table.insert(complicated, l)
       return
     end
-    end)()
+    end)(raw_l)
   end
   if valid_rule then
     insert_cur_rule()