From 8e5237cca1bf70ffe00291f48484d87b485908c8 Mon Sep 17 00:00:00 2001 From: linuxdaemon Date: Thu, 25 Jan 2018 16:07:30 -0600 Subject: Make sure banredirect metadata can not be duplicated --- src/modules/m_banredirect.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/modules') diff --git a/src/modules/m_banredirect.cpp b/src/modules/m_banredirect.cpp index 1b9e361bf..a0c9bc750 100644 --- a/src/modules/m_banredirect.cpp +++ b/src/modules/m_banredirect.cpp @@ -40,9 +40,17 @@ class BanRedirectEntry : targetchan(target), banmask(mask) { } + + bool operator<(const BanRedirectEntry& other) const + { + if (this->targetchan < other.targetchan) + return true; + + return this->banmask < other.banmask; + } }; -typedef std::vector BanRedirectList; +typedef std::set BanRedirectList; typedef std::deque StringDeque; class BanRedirect : public ModeWatcher @@ -180,7 +188,7 @@ class BanRedirect : public ModeWatcher } /* Here 'param' doesn't have the channel on it yet */ - redirects->push_back(BanRedirectEntry(mask[CHAN], param)); + redirects->insert(BanRedirectEntry(mask[CHAN], param)); /* Now it does */ param.append(mask[CHAN]); @@ -259,7 +267,7 @@ class ModuleBanRedirect : public Module for(BanRedirectList::iterator i = redirects->begin(); i != redirects->end(); i++) { - modestack.Push('b', i->targetchan.insert(0, i->banmask)); + modestack.Push('b', i->banmask + i->targetchan); } for(BanRedirectList::iterator i = redirects->begin(); i != redirects->end(); i++) -- cgit v1.2.3 From cf9fb00675cac902751f922018e4827f425dbca1 Mon Sep 17 00:00:00 2001 From: linuxdaemon Date: Thu, 25 Jan 2018 19:12:23 -0600 Subject: Fix comparator logic for ordering by channel --- src/modules/m_banredirect.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/modules') diff --git a/src/modules/m_banredirect.cpp b/src/modules/m_banredirect.cpp index a0c9bc750..64a5855ae 100644 --- a/src/modules/m_banredirect.cpp +++ b/src/modules/m_banredirect.cpp @@ -43,10 +43,10 @@ class BanRedirectEntry bool operator<(const BanRedirectEntry& other) const { - if (this->targetchan < other.targetchan) - return true; + if (targetchan != other.targetchan) + return targetchan < other.targetchan; - return this->banmask < other.banmask; + return banmask < other.banmask; } }; -- cgit v1.2.3 From 219e01b5ce7588efc5da9b8c5d1ce8e7a629b462 Mon Sep 17 00:00:00 2001 From: linuxdaemon Date: Thu, 25 Jan 2018 21:34:40 -0600 Subject: Revert std::set changes and add duplicate checking in m_banredirect instead, as requested by @Adam- --- src/modules/m_banredirect.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'src/modules') diff --git a/src/modules/m_banredirect.cpp b/src/modules/m_banredirect.cpp index 64a5855ae..1d35c2934 100644 --- a/src/modules/m_banredirect.cpp +++ b/src/modules/m_banredirect.cpp @@ -40,17 +40,9 @@ class BanRedirectEntry : targetchan(target), banmask(mask) { } - - bool operator<(const BanRedirectEntry& other) const - { - if (targetchan != other.targetchan) - return targetchan < other.targetchan; - - return banmask < other.banmask; - } }; -typedef std::set BanRedirectList; +typedef std::vector BanRedirectList; typedef std::deque StringDeque; class BanRedirect : public ModeWatcher @@ -186,9 +178,24 @@ class BanRedirect : public ModeWatcher redirects = new BanRedirectList; extItem.set(channel, redirects); } + else + { + for (BanRedirectList::iterator redir = redirects->begin(); redir != redirects->end(); ++redir) + { + // Mimic the functionality used when removing the mode + if ((irc::string(redir->targetchan.c_str()) == irc::string(mask[CHAN].c_str())) && (irc::string(redir->banmask.c_str()) == irc::string(param.c_str()))) + { + // Make sure the +b handler will still set the right ban + param.append(mask[CHAN]); + // Silently ignore the duplicate and don't set metadata + // This still allows channel ops to set/unset a redirect ban to clear "ghost" redirects + return true; + } + } + } /* Here 'param' doesn't have the channel on it yet */ - redirects->insert(BanRedirectEntry(mask[CHAN], param)); + redirects->push_back(BanRedirectEntry(mask[CHAN], param)); /* Now it does */ param.append(mask[CHAN]); @@ -267,7 +274,7 @@ class ModuleBanRedirect : public Module for(BanRedirectList::iterator i = redirects->begin(); i != redirects->end(); i++) { - modestack.Push('b', i->banmask + i->targetchan); + modestack.Push('b', i->targetchan.insert(0, i->banmask)); } for(BanRedirectList::iterator i = redirects->begin(); i != redirects->end(); i++) -- cgit v1.2.3