From 34e5aedc45dfc431324442d22a330d1ad4af68e1 Mon Sep 17 00:00:00 2001 From: Daniel Folkinshteyn Date: Sun, 8 Aug 2010 01:43:05 -0400 Subject: [PATCH] String: make re timeout configurable. Signed-off-by: James McCoy --- plugins/String/config.py | 7 +++++++ plugins/String/plugin.py | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/String/config.py b/plugins/String/config.py index e4f1840ad..3992d9631 100644 --- a/plugins/String/config.py +++ b/plugins/String/config.py @@ -50,5 +50,12 @@ conf.registerGlobalValue(String.levenshtein, 'max', and more time. Using nested commands, strings can get quite large, hence this variable, to limit the size of arguments passed to the levenshtein command.""")) +conf.registerGroup(String, 're') +conf.registerGlobalValue(String.re, 'timeout', + registry.PositiveFloat(5, """Determines the maximum time, in seconds, that + a regular expression is given to execute before being terminated. Since + there is a possibility that user input for the re command can cause it to + eat up large amounts of ram or cpu time, it's a good idea to keep this + low. Most normal regexps should not take very long at all.""")) # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: diff --git a/plugins/String/plugin.py b/plugins/String/plugin.py index 9b4719489..ef0e2cfac 100644 --- a/plugins/String/plugin.py +++ b/plugins/String/plugin.py @@ -141,7 +141,8 @@ class String(callbacks.Plugin): s = 'You probably don\'t want to match the empty string.' irc.error(s) else: - v = commands.process(f, text, timeout=10, pn=self.name(), cn='re') + t = self.registryValue('re.timeout') + v = commands.process(f, text, timeout=t, pn=self.name(), cn='re') irc.reply(v) re = thread(wrap(re, [first('regexpMatcher', 'regexpReplacer'), 'text']))