From: Vsevolod Stakhov Date: Sat, 11 Jul 2026 09:30:34 +0000 (+0100) Subject: [Fix] Lua 5.5 compatibility: do not assign to for-loop variables X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dfbc851ddec576215485fa069e3b4f152c0f3988;p=thirdparty%2Frspamd.git [Fix] Lua 5.5 compatibility: do not assign to for-loop variables 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. --- diff --git a/lualib/lua_aliases.lua b/lualib/lua_aliases.lua index a49d8ddc68..15c068d0eb 100644 --- a/lualib/lua_aliases.lua +++ b/lualib/lua_aliases.lua @@ -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 diff --git a/lualib/lua_cfg_transform.lua b/lualib/lua_cfg_transform.lua index f137dea30f..2c23964253 100644 --- a/lualib/lua_cfg_transform.lua +++ b/lualib/lua_cfg_transform.lua @@ -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 diff --git a/lualib/plugins/dmarc.lua b/lualib/plugins/dmarc.lua index 6e8883f9d1..7d2f6eb2cb 100644 --- a/lualib/plugins/dmarc.lua +++ b/lualib/plugins/dmarc.lua @@ -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 diff --git a/src/plugins/lua/clickhouse.lua b/src/plugins/lua/clickhouse.lua index a0075b7619..4d85b5c64c 100644 --- a/src/plugins/lua/clickhouse.lua +++ b/src/plugins/lua/clickhouse.lua @@ -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) diff --git a/src/plugins/lua/spamassassin.lua b/src/plugins/lua/spamassassin.lua index c03481de21..fcbd4102a5 100644 --- a/src/plugins/lua/spamassassin.lua +++ b/src/plugins/lua/spamassassin.lua @@ -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() diff --git a/utils/sa_trivial_convert.lua b/utils/sa_trivial_convert.lua index 2ea53bed1e..6e7c1f6f3b 100644 --- a/utils/sa_trivial_convert.lua +++ b/utils/sa_trivial_convert.lua @@ -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()