From a0a02fe0e0e06d8c9839c965765eff5cf833a837 Mon Sep 17 00:00:00 2001 From: "silver%warwickcompsoc.co.uk" Date: Tue, 18 Jul 2006 17:01:10 +0000 Subject: [PATCH] Bug 269739 - Limit command recursion to 10 levels. ChatZilla only. r=samuel --- extensions/irc/js/lib/command-manager.js | 3 ++ extensions/irc/xul/content/commands.js | 28 +++++++++++++++++++ extensions/irc/xul/content/static.js | 2 +- .../irc/xul/locale/en-US/chatzilla.properties | 3 +- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/extensions/irc/js/lib/command-manager.js b/extensions/irc/js/lib/command-manager.js index 11bedee9cb3c..a11761c366cd 100644 --- a/extensions/irc/js/lib/command-manager.js +++ b/extensions/irc/js/lib/command-manager.js @@ -172,6 +172,9 @@ function CommandManager (defaultBundle) { this.commands = new Object(); this.defaultBundle = defaultBundle; + this.currentDispatchDepth = 0; + this.maxDispatchDepth = 10; + this.dispatchUnwinding = false; } CommandManager.prototype.defaultFlags = 0; diff --git a/extensions/irc/xul/content/commands.js b/extensions/irc/xul/content/commands.js index 7a595651e11f..479c0a4acefa 100644 --- a/extensions/irc/xul/content/commands.js +++ b/extensions/irc/xul/content/commands.js @@ -381,6 +381,21 @@ function dispatch(text, e, isInteractive, flags) case 1: /* one match, good for you */ + var cm = client.commandManager; + + if (cm.currentDispatchDepth >= cm.maxDispatchDepth) + { + /* We've reatched the max dispatch depth, so we need to unwind + * the entire stack of commands. + */ + cm.dispatchUnwinding = true; + } + // Don't start any new commands while unwinding. + if (cm.dispatchUnwinding) + break; + + cm.currentDispatchDepth++; + var ex; try { @@ -396,6 +411,19 @@ function dispatch(text, e, isInteractive, flags) else dd(formatException(ex), MT_ERROR); } + + cm.currentDispatchDepth--; + if (cm.dispatchUnwinding && (cm.currentDispatchDepth == 0)) + { + /* Last level to unwind, and this is where we display the + * message. We need to leave it until here because displaying + * a message invokes a couple of commands itself, and we need + * to not be right on the dispatch limit for that. + */ + cm.dispatchUnwinding = false; + display(getMsg(MSG_ERR_MAX_DISPATCH_DEPTH, ary[0].name), + MT_ERROR); + } break; default: diff --git a/extensions/irc/xul/content/static.js b/extensions/irc/xul/content/static.js index 28b6d8cf2161..b501669b73a0 100644 --- a/extensions/irc/xul/content/static.js +++ b/extensions/irc/xul/content/static.js @@ -43,7 +43,7 @@ const __cz_version = "0.9.74"; const __cz_condition = "green"; const __cz_suffix = ""; const __cz_guid = "59c81df5-4b7a-477b-912d-4e0fdf64e5f2"; -const __cz_locale = "0.9.74"; +const __cz_locale = "0.9.74.1"; var warn; var ASSERT; diff --git a/extensions/irc/xul/locale/en-US/chatzilla.properties b/extensions/irc/xul/locale/en-US/chatzilla.properties index 0f2ca683c092..bc60746c11d0 100644 --- a/extensions/irc/xul/locale/en-US/chatzilla.properties +++ b/extensions/irc/xul/locale/en-US/chatzilla.properties @@ -69,7 +69,7 @@ # ### End of notes ### -locale.version = 0.9.74 +locale.version = 0.9.74.1 locale.error = You are using ChatZilla %1$S, which requires the locale version %2$S. The currently selected locale, %3$S, is version %4$S, and therefore there may be problems running ChatZilla.\n\nIt is strongly advised that you update or remove the ChatZilla locale in question. # Misc @@ -709,6 +709,7 @@ msg.err.notimplemented = Sorry, ``%1$S'' has not been implemented. msg.err.required.param = Missing required parameter %1$S. msg.err.ambigcommand = Ambiguous command, ``%1$S'', %2$S commands match [%3$S]. msg.err.required.nr.param = Missing %1$S parameters. This alias requires at least %2$S parameters. +msg.err.max.dispatch.depth = Reached max dispatch depth while attempting to dispatch ``%1$S''. ## chatzilla error messages ## msg.err.invalid.pref = Invalid value for preference %1$S (%2$S).