aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/factoids/sandbox.lua
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2018-02-23 18:29:20 +0100
committerJokler <jokler.contact@gmail.com>2018-02-23 18:29:20 +0100
commit297ceaa0899a6228f47f1f14e4bd261ec4cc6619 (patch)
treeb97f3cc18306ceb4fe0a4fc2330f9f402c8c3f5c /src/plugins/factoids/sandbox.lua
parent806614b5bf00581c9a564fcda4ecb760b6d27c6a (diff)
downloadfrippy-297ceaa0899a6228f47f1f14e4bd261ec4cc6619.tar.gz
frippy-297ceaa0899a6228f47f1f14e4bd261ec4cc6619.zip
Add possibly unsafe timeout hook to factoids
Diffstat (limited to 'src/plugins/factoids/sandbox.lua')
-rw-r--r--src/plugins/factoids/sandbox.lua17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/plugins/factoids/sandbox.lua b/src/plugins/factoids/sandbox.lua
index 8ebf518..3fde65e 100644
--- a/src/plugins/factoids/sandbox.lua
+++ b/src/plugins/factoids/sandbox.lua
@@ -24,9 +24,26 @@ local env = { print = send,
table = table,
string = string,
tostring = tostring,
+ tonumber = tonumber,
math = math }
local f, e = load(factoid, nil, nil, env)
+
+-- Check if the factoid timed out
+function checktime(event, line)
+ if os.time() - time >= timeout then
+ error("Timed out after " .. timeout .. " seconds", 0)
+ else
+ -- Limit the cpu usage of factoids
+ sleep(1)
+ end
+end
+
+-- Add timeout hook
+time = os.time()
+timeout = 30
+debug.sethook(checktime, "l")
+
if f then
f()
else