1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-09-15 18:57:08 +00:00

[CSM] Improve security for client-sided mods (#5100)

This commit is contained in:
red-001 2017-01-28 16:24:25 +00:00 committed by Loïc Blot
parent 92b45b2a18
commit a50d07d39a
6 changed files with 172 additions and 30 deletions

View file

@ -1,6 +1,9 @@
core.callback_origins = {}
local getinfo = debug.getinfo
debug.getinfo = nil
function core.run_callbacks(callbacks, mode, ...)
assert(type(callbacks) == "table")
local cb_len = #callbacks
@ -47,7 +50,7 @@ local function make_registration()
t[#t + 1] = func
core.callback_origins[func] = {
mod = core.get_current_modname() or "??",
name = debug.getinfo(1, "n").name or "??"
name = getinfo(1, "n").name or "??"
}
--local origin = core.callback_origins[func]
--print(origin.name .. ": " .. origin.mod .. " registering cbk " .. tostring(func))

View file

@ -3,6 +3,7 @@
-- This ignores mod namespaces (variables with the same name as the current mod).
local WARN_INIT = false
local getinfo = debug.getinfo
function core.global_exists(name)
if type(name) ~= "string" then
@ -18,7 +19,7 @@ local declared = {}
local warned = {}
function meta:__newindex(name, value)
local info = debug.getinfo(2, "Sl")
local info = getinfo(2, "Sl")
local desc = ("%s:%d"):format(info.short_src, info.currentline)
if not declared[name] then
local warn_key = ("%s\0%d\0%s"):format(info.source,
@ -42,7 +43,7 @@ end
function meta:__index(name)
local info = debug.getinfo(2, "Sl")
local info = getinfo(2, "Sl")
local warn_key = ("%s\0%d\0%s"):format(info.source, info.currentline, name)
if not declared[name] and not warned[warn_key] and info.what ~= "C" then
core.log("warning", ("Undeclared global variable %q accessed at %s:%s")

View file

@ -47,6 +47,7 @@ elseif INIT == "mainmenu" then
elseif INIT == "async" then
dofile(asyncpath .. "init.lua")
elseif INIT == "client" then
os.setlocale = nil
dofile(clientpath .. "init.lua")
else
error(("Unrecognized builtin initialization type %s!"):format(tostring(INIT)))