client: Sandbox works
This commit is contained in:
parent
7fb086e399
commit
7557a1a318
@ -5,6 +5,9 @@ function buildat:Logger(module)
|
|||||||
function logger:info(text)
|
function logger:info(text)
|
||||||
print(os.date("%b %d %H:%M:%S "..module..": "..text))
|
print(os.date("%b %d %H:%M:%S "..module..": "..text))
|
||||||
end
|
end
|
||||||
|
function logger:error(text)
|
||||||
|
print(os.date("%b %d %H:%M:%S "..module.." ERROR: "..text))
|
||||||
|
end
|
||||||
return logger
|
return logger
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -36,17 +39,30 @@ function buildat:send_packet(name, data)
|
|||||||
__buildat_send_packet(name, data)
|
__buildat_send_packet(name, data)
|
||||||
end
|
end
|
||||||
|
|
||||||
function buildat:run_script_file(name)
|
local sandbox_env = {
|
||||||
local content = __buildat_get_file_content(name)
|
buildat = buildat,
|
||||||
if not content then
|
}
|
||||||
return false
|
|
||||||
end
|
local function run_in_sandbox(untrusted_code)
|
||||||
log:info("buildat:run_script_file("..name.."): #content="..#content)
|
if untrusted_code:byte(1) == 27 then return nil, "binary bytecode prohibited" end
|
||||||
local script, err = loadstring(content)
|
local untrusted_function, message = loadstring(untrusted_code)
|
||||||
if not script then
|
if not untrusted_function then return nil, message end
|
||||||
log:error("Failed to load script: "+err)
|
setfenv(untrusted_function, sandbox_env)
|
||||||
return false
|
return pcall(untrusted_function)
|
||||||
end
|
|
||||||
script()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function buildat:run_script_file(name)
|
||||||
|
local code = __buildat_get_file_content(name)
|
||||||
|
if not code then
|
||||||
|
log:error("Failed to load script file: "+name)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
log:info("buildat:run_script_file("..name.."): #code="..#code)
|
||||||
|
local status, err = run_in_sandbox(code)
|
||||||
|
--local status, err = run_in_sandbox([[buildat:Logger("foo"):info("Pihvi")]])
|
||||||
|
if status == false then
|
||||||
|
log:error("Failed to run script: "..err)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user