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, ...)

View File

@ -83,6 +83,10 @@ describe('sandbox.run', function()
assert_error(function() sandbox.run("for i=1,100 do end", {quota = 20}) end)
end)
it('does not use quotes if the quote param is false', function()
assert_not_error(function() sandbox.run("for i=1,1000000 do end", {quota = false}) end)
end)
end)