feat(sandbox) explicitly drop support of quotas on LuaJIT

The solution we use in PUC Rio Lua (with debug.sethook) simply does not
work in LuaJIT.

* We have added a `sandbox.quota_supported` field to signal this feature
  (or lack of thereof)
* We explicitly return an error if `options.quota` is passed on a LuaJIT
  environment, in order to prevent LuaJIT users from believing that they
  are protected against infinite loops.
This commit is contained in:
Enrique García Cota
2021-01-05 00:43:04 +01:00
committed by Enrique García Cota
parent 50bfa4abca
commit 485a14697c
3 changed files with 34 additions and 21 deletions

View File

@@ -65,7 +65,7 @@ sandbox.run('while true do end') -- raise errors after 500000 instructions
sandbox.run('while true do end', {quota=10000}) -- raise error after 10000 instructions
```
Note that if the quota is low enough, sandboxed functions that do lots of calculations might fail:
If the quota is low enough, sandboxed functions that do lots of calculations might fail:
``` lua
local f = function()
@@ -77,6 +77,8 @@ end
sandbox.run(f, {quota=100}) -- raises error before the function ends
```
Note: This feature is not available in LuaJIT
### options.env
Use the `env` option to inject additional variables to the environment in which the sandboxed function is executed.