From 7477e74d679e47ef11e7ecc012cee0de90ab10be Mon Sep 17 00:00:00 2001 From: Desour Date: Tue, 25 Mar 2025 13:45:22 +0100 Subject: [PATCH 1/3] unset debug.getinfo --- .luacheckrc | 6 ++++++ builtin/common/register.lua | 5 +++-- builtin/common/strict.lua | 6 +++--- builtin/game/register.lua | 5 +++-- builtin/profiler/instrumentation.lua | 3 ++- src/script/cpp_api/s_security.cpp | 2 +- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index ae6aa728ee..c98397085a 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -47,6 +47,12 @@ files["builtin/client/register.lua"] = { } } +files["builtin/sscsm_client/init.lua"] = { + globals = { + debug = {fields={"getinfo"}}, + } +} + files["builtin/common/math.lua"] = { globals = { "math", diff --git a/builtin/common/register.lua b/builtin/common/register.lua index cbeac7c64f..9ad8a16fb6 100644 --- a/builtin/common/register.lua +++ b/builtin/common/register.lua @@ -1,4 +1,5 @@ local builtin_shared = ... +local debug_getinfo = debug.getinfo do local default = {mod = "??", name = "??"} @@ -56,7 +57,7 @@ function builtin_shared.make_registration() core.callback_origins[func] = { -- may be nil or return nil mod = core.get_current_modname and core.get_current_modname() or "??", - name = debug.getinfo(1, "n").name or "??" + name = debug_getinfo(1, "n").name or "??" } end return t, registerfunc @@ -69,7 +70,7 @@ function builtin_shared.make_registration_reverse() core.callback_origins[func] = { -- may be nil or return nil mod = core.get_current_modname and core.get_current_modname() or "??", - name = debug.getinfo(1, "n").name or "??" + name = debug_getinfo(1, "n").name or "??" } end return t, registerfunc diff --git a/builtin/common/strict.lua b/builtin/common/strict.lua index b3c4ccce46..c2c673aa6f 100644 --- a/builtin/common/strict.lua +++ b/builtin/common/strict.lua @@ -1,4 +1,4 @@ -local getinfo, rawget, rawset = debug.getinfo, rawget, rawset +local debug_getinfo, rawget, rawset = debug.getinfo, rawget, rawset function core.global_exists(name) if type(name) ~= "string" then @@ -18,7 +18,7 @@ function meta:__newindex(name, value) if declared[name] then return end - local info = getinfo(2, "Sl") + local info = debug_getinfo(2, "Sl") if info ~= nil then local desc = ("%s:%d"):format(info.short_src, info.currentline) local warn_key = ("%s\0%d\0%s"):format(info.source, info.currentline, name) @@ -36,7 +36,7 @@ function meta:__index(name) if declared[name] then return end - local info = getinfo(2, "Sl") + local info = debug_getinfo(2, "Sl") if info == nil then return end diff --git a/builtin/game/register.lua b/builtin/game/register.lua index b832ccc6db..cc2f5fe980 100644 --- a/builtin/game/register.lua +++ b/builtin/game/register.lua @@ -1,5 +1,6 @@ local builtin_shared = ... local S = core.get_translator("__builtin") +local debug_getinfo = debug.getinfo -- -- Make raw registration functions inaccessible to anyone except this file @@ -548,7 +549,7 @@ function core.registered_on_player_hpchange(player, hp_change, reason) local func = core.registered_on_player_hpchanges.modifiers[i] hp_change, last = func(player, hp_change, reason) if type(hp_change) ~= "number" then - local debuginfo = debug.getinfo(func) + local debuginfo = debug_getinfo(func) error("The register_on_hp_changes function has to return a number at " .. debuginfo.short_src .. " line " .. debuginfo.linedefined) end @@ -570,7 +571,7 @@ function core.register_on_player_hpchange(func, modifier) end core.callback_origins[func] = { mod = core.get_current_modname() or "??", - name = debug.getinfo(1, "n").name or "??" + name = debug_getinfo(1, "n").name or "??" } end diff --git a/builtin/profiler/instrumentation.lua b/builtin/profiler/instrumentation.lua index 2b34295daf..39947cc7ef 100644 --- a/builtin/profiler/instrumentation.lua +++ b/builtin/profiler/instrumentation.lua @@ -5,6 +5,7 @@ local format, ipairs, type = string.format, ipairs, type local core, get_current_modname = core, core.get_current_modname local profiler, sampler = ... +local debug_getinfo = debug.getinfo local instrument_builtin = core.settings:get_bool("instrument.builtin", false) @@ -67,7 +68,7 @@ local worldmods_path = regex_escape(core.get_worldpath()) local user_path = regex_escape(core.get_user_path()) local builtin_path = regex_escape(core.get_builtin_path()) local function generate_source_location(def) - local info = debug.getinfo(def.func) + local info = debug_getinfo(def.func) local modpath = regex_escape(core.get_modpath(def.mod) or "") local source = info.source if modpath ~= "" then diff --git a/src/script/cpp_api/s_security.cpp b/src/script/cpp_api/s_security.cpp index 834650fdc6..021b46eadf 100644 --- a/src/script/cpp_api/s_security.cpp +++ b/src/script/cpp_api/s_security.cpp @@ -309,7 +309,7 @@ void ScriptApiSecurity::initializeSecurityClient() "time" }; static const char *debug_whitelist[] = { - "getinfo", // used by builtin and unset before mods load + "getinfo", // used by builtin and unset before mods load <- FIXME: doesn't actually happen "traceback" }; From 75b28a56e663374a2479c752b512e4bfb7f3f48a Mon Sep 17 00:00:00 2001 From: Desour Date: Tue, 25 Mar 2025 13:47:14 +0100 Subject: [PATCH 2/3] fix debug.getinfo not being unset in CPCSM (regression) was introduced in eeb6cab --- .luacheckrc | 2 +- builtin/client/init.lua | 3 +++ src/script/cpp_api/s_security.cpp | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index c98397085a..54cf9e3a2a 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -41,7 +41,7 @@ stds.menu_common = { }, } -files["builtin/client/register.lua"] = { +files["builtin/client/init.lua"] = { globals = { debug = {fields={"getinfo"}}, } diff --git a/builtin/client/init.lua b/builtin/client/init.lua index ee0f267db7..769fbe56cb 100644 --- a/builtin/client/init.lua +++ b/builtin/client/init.lua @@ -13,3 +13,6 @@ dofile(commonpath .. "information_formspecs.lua") dofile(clientpath .. "chatcommands.lua") dofile(clientpath .. "misc.lua") assert(loadfile(commonpath .. "item_s.lua"))({}) -- Just for push/read node functions + +-- unset, as promised in initializeSecurityClient() +debug.getinfo = nil diff --git a/src/script/cpp_api/s_security.cpp b/src/script/cpp_api/s_security.cpp index 021b46eadf..834650fdc6 100644 --- a/src/script/cpp_api/s_security.cpp +++ b/src/script/cpp_api/s_security.cpp @@ -309,7 +309,7 @@ void ScriptApiSecurity::initializeSecurityClient() "time" }; static const char *debug_whitelist[] = { - "getinfo", // used by builtin and unset before mods load <- FIXME: doesn't actually happen + "getinfo", // used by builtin and unset before mods load "traceback" }; From 5d5786be7a1568f3ea6e8cc168adad76acee451f Mon Sep 17 00:00:00 2001 From: Desour Date: Mon, 22 Sep 2025 19:48:44 +0200 Subject: [PATCH 3/3] remove sscsm remains --- .luacheckrc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 54cf9e3a2a..9ed9c7817e 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -47,12 +47,6 @@ files["builtin/client/init.lua"] = { } } -files["builtin/sscsm_client/init.lua"] = { - globals = { - debug = {fields={"getinfo"}}, - } -} - files["builtin/common/math.lua"] = { globals = { "math",