1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

unset debug.getinfo

This commit is contained in:
Desour 2025-03-25 13:45:22 +01:00
parent 1be9c614d1
commit 051e824787
7 changed files with 22 additions and 10 deletions

View file

@ -46,6 +46,12 @@ files["builtin/client/register.lua"] = {
} }
} }
files["builtin/sscsm_client/init.lua"] = {
globals = {
debug = {fields={"getinfo"}},
}
}
files["builtin/common/math.lua"] = { files["builtin/common/math.lua"] = {
globals = { globals = {
"math", "math",

View file

@ -1,4 +1,5 @@
local builtin_shared = ... local builtin_shared = ...
local debug_getinfo = debug.getinfo
do do
local default = {mod = "??", name = "??"} local default = {mod = "??", name = "??"}
@ -56,7 +57,7 @@ function builtin_shared.make_registration()
core.callback_origins[func] = { core.callback_origins[func] = {
-- may be nil or return nil -- may be nil or return nil
mod = core.get_current_modname and core.get_current_modname() or "??", 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 end
return t, registerfunc return t, registerfunc
@ -69,7 +70,7 @@ function builtin_shared.make_registration_reverse()
core.callback_origins[func] = { core.callback_origins[func] = {
-- may be nil or return nil -- may be nil or return nil
mod = core.get_current_modname and core.get_current_modname() or "??", 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 end
return t, registerfunc return t, registerfunc

View file

@ -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) function core.global_exists(name)
if type(name) ~= "string" then if type(name) ~= "string" then
@ -18,7 +18,7 @@ function meta:__newindex(name, value)
if declared[name] then if declared[name] then
return return
end end
local info = getinfo(2, "Sl") local info = debug_getinfo(2, "Sl")
if info ~= nil then if info ~= nil then
local desc = ("%s:%d"):format(info.short_src, info.currentline) local desc = ("%s:%d"):format(info.short_src, info.currentline)
local warn_key = ("%s\0%d\0%s"):format(info.source, info.currentline, name) 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 if declared[name] then
return return
end end
local info = getinfo(2, "Sl") local info = debug_getinfo(2, "Sl")
if info == nil then if info == nil then
return return
end end

View file

@ -1,5 +1,6 @@
local builtin_shared = ... local builtin_shared = ...
local S = core.get_translator("__builtin") local S = core.get_translator("__builtin")
local debug_getinfo = debug.getinfo
-- --
-- Make raw registration functions inaccessible to anyone except this file -- 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] local func = core.registered_on_player_hpchanges.modifiers[i]
hp_change, last = func(player, hp_change, reason) hp_change, last = func(player, hp_change, reason)
if type(hp_change) ~= "number" then 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 " .. error("The register_on_hp_changes function has to return a number at " ..
debuginfo.short_src .. " line " .. debuginfo.linedefined) debuginfo.short_src .. " line " .. debuginfo.linedefined)
end end
@ -570,7 +571,7 @@ function core.register_on_player_hpchange(func, modifier)
end end
core.callback_origins[func] = { core.callback_origins[func] = {
mod = core.get_current_modname() or "??", mod = core.get_current_modname() or "??",
name = debug.getinfo(1, "n").name or "??" name = debug_getinfo(1, "n").name or "??"
} }
end end

View file

@ -5,6 +5,7 @@
local format, pairs, type = string.format, pairs, type local format, pairs, type = string.format, pairs, type
local core, get_current_modname = core, core.get_current_modname local core, get_current_modname = core, core.get_current_modname
local profiler, sampler, get_bool_default = ... local profiler, sampler, get_bool_default = ...
local debug_getinfo = debug.getinfo
local instrument_builtin = get_bool_default("instrument.builtin", false) local instrument_builtin = get_bool_default("instrument.builtin", false)
@ -59,7 +60,7 @@ local function generate_name(def)
local index_id = def.mod .. (class or func_name) local index_id = def.mod .. (class or func_name)
local index = counts[index_id] or 1 local index = counts[index_id] or 1
counts[index_id] = index + 1 counts[index_id] = index + 1
local info = debug.getinfo(def.func) local info = debug_getinfo(def.func)
local modpath = regex_escape(core.get_modpath(def.mod) or "") local modpath = regex_escape(core.get_modpath(def.mod) or "")
local source = info.source local source = info.source
if modpath ~= "" then if modpath ~= "" then

View file

@ -20,3 +20,6 @@ assert(loadfile(commonpath .. "register.lua"))(builtin_shared)
assert(loadfile(mypath .. "register.lua"))(builtin_shared) assert(loadfile(mypath .. "register.lua"))(builtin_shared)
dofile(commonpath .. "after.lua") dofile(commonpath .. "after.lua")
-- unset, as promised in initializeSecuritySSCSM()
debug.getinfo = nil

View file

@ -311,7 +311,7 @@ void ScriptApiSecurity::initializeSecurityClient()
"time" "time"
}; };
static const char *debug_whitelist[] = { 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" "traceback"
}; };
@ -417,7 +417,7 @@ void ScriptApiSecurity::initializeSecuritySSCSM()
"time" "time"
}; };
static const char *debug_whitelist[] = { static const char *debug_whitelist[] = {
"getinfo", // used by builtin and unset before mods load //TODO "getinfo", // used by client builtin and unset before mods load
"traceback" "traceback"
}; };
static const char *string_whitelist[] = { // all but string.dump static const char *string_whitelist[] = { // all but string.dump