diff options
author | Adam <Adam@anope.org> | 2014-05-13 22:57:53 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2014-05-13 22:57:53 -0400 |
commit | 63b02b8c97e73d5a1fc7005e9693a954179ded0d (patch) | |
tree | 84d67d16b8f984eef67653c7a50f7154aa33bb23 /src | |
parent | 1c8a77ab9f4adfd0afd8217bc462bb338925dcea (diff) |
Sanitize nuh masks more to prevent the other side from rewriting them, which screws with our internal tracking of them
Diffstat (limited to 'src')
-rw-r--r-- | src/channels.cpp | 12 | ||||
-rw-r--r-- | src/modes.cpp | 19 | ||||
-rw-r--r-- | src/protocol.cpp | 5 |
3 files changed, 30 insertions, 6 deletions
diff --git a/src/channels.cpp b/src/channels.cpp index b705c8584..409cf6b55 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -400,6 +400,7 @@ void Channel::RemoveModeInternal(MessageSource &setter, ChannelMode *ocm, const void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, bool enforce_mlock) { + Anope::string wparam = param; if (!cm) return; /* Don't set modes already set */ @@ -408,11 +409,11 @@ void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, else if (cm->type == MODE_PARAM) { ChannelModeParam *cmp = anope_dynamic_static_cast<ChannelModeParam *>(cm); - if (!cmp->IsValid(param)) + if (!cmp->IsValid(wparam)) return; Anope::string cparam; - if (GetParam(cm->name, cparam) && cparam.equals_cs(param)) + if (GetParam(cm->name, cparam) && cparam.equals_cs(wparam)) return; } else if (cm->type == MODE_STATUS) @@ -424,7 +425,11 @@ void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, else if (cm->type == MODE_LIST) { ChannelModeList *cml = anope_dynamic_static_cast<ChannelModeList *>(cm); - if (this->HasMode(cm->name, param) || !cml->IsValid(param)) + + if (!cml->IsValid(wparam)) + return; + + if (this->HasMode(cm->name, wparam)) return; } @@ -439,7 +444,6 @@ void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, this->chanserv_modecount++; } - Anope::string wparam = param; ChannelMode *wcm = cm->Wrap(wparam); ModeManager::StackerAdd(bi, this, wcm, true, wparam); diff --git a/src/modes.cpp b/src/modes.cpp index 668f7c150..4138cfebe 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -175,6 +175,13 @@ ChannelModeList::ChannelModeList(const Anope::string &cm, char mch) : ChannelMod this->type = MODE_LIST; } +bool ChannelModeList::IsValid(Anope::string &mask) const +{ + if (name == "BAN" || name == "EXCEPT" || name == "INVITEOVERRIDE") + mask = IRCD->NormalizeMask(mask); + return true; +} + ChannelModeParam::ChannelModeParam(const Anope::string &cm, char mch, bool ma) : ChannelMode(cm, mch), minus_no_arg(ma) { this->type = MODE_PARAM; @@ -231,7 +238,7 @@ bool UserModeNoone::CanSet(User *u) const return false; } -bool ChannelModeKey::IsValid(const Anope::string &value) const +bool ChannelModeKey::IsValid(Anope::string &value) const { if (!value.empty() && value.find(':') == Anope::string::npos && value.find(',') == Anope::string::npos) return true; @@ -796,7 +803,7 @@ Entry::Entry(const Anope::string &m, const Anope::string &fh) : name(m), mask(fh this->host = cidr_ip; - Log(LOG_DEBUG) << "Ban " << this->mask << " has cidr " << this->cidr_len; + Log(LOG_DEBUG) << "Ban " << m << " has cidr " << this->cidr_len; } } catch (const ConvertException &) { } @@ -812,6 +819,14 @@ const Anope::string Entry::GetMask() const return this->mask; } +const Anope::string Entry::GetNUHMask() const +{ + Anope::string n = nick.empty() ? "*" : nick, + u = user.empty() ? "*" : user, + h = host.empty() ? "*" : host; + return n + "!" + u + "@" + h; +} + bool Entry::Matches(User *u, bool full) const { /* First check if this mode has defined any matches (usually for extbans). */ diff --git a/src/protocol.cpp b/src/protocol.cpp index 89e4a3c86..a32f521f2 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -387,6 +387,11 @@ unsigned IRCDProto::GetMaxListFor(Channel *c) return c->HasMode("LBAN") ? 0 : Config->GetBlock("networkinfo")->Get<int>("modelistsize"); } +Anope::string IRCDProto::NormalizeMask(const Anope::string &mask) +{ + return Entry("", mask).GetNUHMask(); +} + MessageSource::MessageSource(const Anope::string &src) : source(src), u(NULL), s(NULL) { /* no source for incoming message is our uplink */ |