added io library isolation so logic functions cant access the io functions
This commit is contained in:
22
sim/iosafe.lua
Normal file
22
sim/iosafe.lua
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
assert(not io.safe, "re-execution of iosafe")
|
||||
|
||||
local iosafe = io
|
||||
_G.io = {safe = true}
|
||||
local requiresafe = require
|
||||
_G.require = nil
|
||||
|
||||
local savedir = OPT_SAVE_DIR
|
||||
|
||||
function io.open(fn, mode)
|
||||
fn = fn:gsub("\\", "/")
|
||||
assert(not fn:find("[^a-zA-Z0-9%._ ]"), "illegal character in file name \""..fn.."\"")
|
||||
assert(not fn:find("%.%."), "illegal updir in file name \""..fn.."\"")
|
||||
fn = fn:gsub("^/", "")
|
||||
|
||||
fn = savedir.."/"..fn
|
||||
|
||||
print("access file \""..fn.."\"")
|
||||
|
||||
return iosafe.open(fn, mode)
|
||||
end
|
||||
Reference in New Issue
Block a user