This commit is contained in:
rdococ 2023-04-27 02:45:24 -07:00 committed by GitHub
commit 8b6694bdbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 2 deletions

View File

@ -232,12 +232,25 @@ end
local function safe_string_find(...) local function safe_string_find(...)
if (select(4, ...)) ~= true then if (select(4, ...)) ~= true then
debug.sethook() -- Clear hook debug.sethook() -- Clear hook
error("string.find: 'plain' (fourth parameter) must always be true in a Luacontroller") error("string.find: 'plain' (fourth parameter) must always be true in a Luacontroller", 2)
end end
return string.find(...) return string.find(...)
end end
-- pcall can capture certain errors after the debug hook is removed.
-- Detect these errors, and propagate them.
local function safe_pcall(f, ...)
local values = {pcall(f, ...)}
local ok, err = values[1], values[2]
if not debug.gethook() then
error(string.gsub(err, "%(load%)%:.+:%s", ""), 2)
end
return unpack(values)
end
local function remove_functions(x) local function remove_functions(x)
local tp = type(x) local tp = type(x)
if tp == "function" then if tp == "function" then
@ -469,7 +482,7 @@ end
local safe_globals = { local safe_globals = {
-- Don't add pcall/xpcall unless willing to deal with the consequences (unless very careful, incredibly likely to allow killing server indirectly) -- Don't add pcall/xpcall unless willing to deal with the consequences (unless very careful, incredibly likely to allow killing server indirectly)
"assert", "error", "ipairs", "next", "pairs", "select", "assert", "error", "ipairs", "next", "pairs", "select",
"tonumber", "tostring", "type", "unpack", "_VERSION" "tonumber", "tostring", "type", "unpack", "_VERSION", "error"
} }
local function create_environment(pos, mem, event, itbl, send_warning) local function create_environment(pos, mem, event, itbl, send_warning)
@ -496,6 +509,7 @@ local function create_environment(pos, mem, event, itbl, send_warning)
print = safe_print, print = safe_print,
interrupt = get_interrupt(pos, itbl, send_warning), interrupt = get_interrupt(pos, itbl, send_warning),
digiline_send = get_digiline_send(pos, itbl, send_warning), digiline_send = get_digiline_send(pos, itbl, send_warning),
pcall = safe_pcall,
string = { string = {
byte = string.byte, byte = string.byte,
char = string.char, char = string.char,