From 0268121676bcd787a980aca0a6ebea36a8564cdd Mon Sep 17 00:00:00 2001 From: dz Date: Fri, 9 Jan 2009 01:12:46 +0000 Subject: Correctly match alias formats (was backwards) and avoid going on to other aliases if none match. Fixes bug #668 reported by Ankit, thanks. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10953 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/m_alias.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp index 423ad8c5b..e3e2e9a5d 100644 --- a/src/modules/m_alias.cpp +++ b/src/modules/m_alias.cpp @@ -139,7 +139,7 @@ class ModuleAlias : public Module virtual int OnPreCommand(std::string &command, std::vector ¶meters, User *user, bool validated, const std::string &original_line) { - std::multimap::iterator i; + std::multimap::iterator i, upperbound; /* If theyre not registered yet, we dont want * to know. @@ -151,6 +151,8 @@ class ModuleAlias : public Module i = Aliases.find(command); if (i == Aliases.end()) return 0; + /* Avoid iterating on to different aliases if no patterns match. */ + upperbound = Aliases.upper_bound(command); irc::string c = command.c_str(); /* The parameters for the command in their original form, with the command stripped off */ @@ -164,7 +166,7 @@ class ModuleAlias : public Module SearchAndReplace(safe, "$", "\r"); - while (i != Aliases.end()) + while (i != upperbound) { if (i->second.UserCommand) { @@ -228,6 +230,9 @@ class ModuleAlias : public Module if (i == Aliases.end()) return 0; + + /* Avoid iterating on to other aliases if no patterns match */ + std::multimap::iterator upperbound = Aliases.upper_bound(fcommand); /* The parameters for the command in their original form, with the command stripped off */ @@ -242,7 +247,7 @@ class ModuleAlias : public Module ServerInstance->Logs->Log("FANTASY", DEBUG, "fantasy: compare is %s and safe is %s", compare.c_str(), safe.c_str()); - while (i != Aliases.end()) + while (i != upperbound) { if (i->second.ChannelCommand) { @@ -266,12 +271,12 @@ class ModuleAlias : public Module { if (a->CaseSensitive) { - if (InspIRCd::Match(compare, a->format, rfc_case_sensitive_map)) + if (!InspIRCd::Match(compare, a->format, rfc_case_sensitive_map)) return 0; } else { - if (InspIRCd::Match(compare, a->format)) + if (!InspIRCd::Match(compare, a->format)) return 0; } } -- cgit v1.2.3