passing false as a quota deactivates the hooks

This commit is contained in:
kikito
2013-09-14 12:54:49 +02:00
parent 48ae2844e9
commit bf995029ba
2 changed files with 16 additions and 5 deletions

View File

@@ -120,19 +120,26 @@ function sandbox.protect(f, options)
options = options or {}
local quota = options.quota or 500000
local quota = false
if options.quota ~= false then
quota = options.quota or 500000
end
local env = merge(options.env or {}, BASE_ENV)
env._G = env._G or env
setfenv(f, env)
return function(...)
local timeout = function()
cleanup()
error('Quota exceeded: ' .. tostring(quota))
if quota then
local timeout = function()
cleanup()
error('Quota exceeded: ' .. tostring(quota))
end
sethook(timeout, "", quota)
end
sethook(timeout, "", quota)
string.rep = nil
local ok, result = pcall(f, ...)