From 297ceaa0899a6228f47f1f14e4bd261ec4cc6619 Mon Sep 17 00:00:00 2001 From: Jokler Date: Fri, 23 Feb 2018 18:29:20 +0100 Subject: Add possibly unsafe timeout hook to factoids --- src/plugins/factoids/sandbox.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/plugins/factoids/sandbox.lua') 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 -- cgit v1.2.3-70-g09d2