From c62b3cb275800555f4e04f294d432dccf909d134 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 2 Jul 2013 01:56:13 -0400 Subject: [PATCH] Fix a few issues found by Attila (invalid array access in channel set events, os_chankill inf loop) --- modules/commands/cs_set.cpp | 16 +++++++++------- modules/commands/cs_set_misc.cpp | 7 ++++--- modules/commands/os_chankill.cpp | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/modules/commands/cs_set.cpp b/modules/commands/cs_set.cpp index d392f6b1d..161b0b725 100644 --- a/modules/commands/cs_set.cpp +++ b/modules/commands/cs_set.cpp @@ -239,6 +239,7 @@ class CommandCSSetDescription : public Command void Execute(CommandSource &source, const std::vector ¶ms) anope_override { ChannelInfo *ci = ChannelInfo::Find(params[0]); + const Anope::string ¶m = params.size() > 1 ? params[1] : ""; if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -246,7 +247,7 @@ class CommandCSSetDescription : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, params[1])); + FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, param)); if (MOD_RESULT == EVENT_STOP) return; @@ -256,9 +257,9 @@ class CommandCSSetDescription : public Command return; } - if (params.size() > 1) + if (!param.empty()) { - ci->desc = params[1]; + ci->desc = param; Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to change the description to " << ci->desc; source.Reply(_("Description of %s changed to \002%s\002."), ci->name.c_str(), ci->desc.c_str()); } @@ -866,6 +867,7 @@ class CommandCSSetSuccessor : public Command void Execute(CommandSource &source, const std::vector ¶ms) anope_override { ChannelInfo *ci = ChannelInfo::Find(params[0]); + const Anope::string ¶m = params.size() > 1 ? params[1] : ""; if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -873,7 +875,7 @@ class CommandCSSetSuccessor : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, params[1])); + FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, param)); if (MOD_RESULT == EVENT_STOP) return; @@ -885,13 +887,13 @@ class CommandCSSetSuccessor : public Command NickCore *nc; - if (params.size() > 1) + if (!param.empty()) { - const NickAlias *na = NickAlias::Find(params[1]); + const NickAlias *na = NickAlias::Find(param); if (!na) { - source.Reply(NICK_X_NOT_REGISTERED, params[1].c_str()); + source.Reply(NICK_X_NOT_REGISTERED, param.c_str()); return; } if (na->nc == ci->GetFounder()) diff --git a/modules/commands/cs_set_misc.cpp b/modules/commands/cs_set_misc.cpp index 5467e2b4e..dfcdc45a0 100644 --- a/modules/commands/cs_set_misc.cpp +++ b/modules/commands/cs_set_misc.cpp @@ -101,6 +101,7 @@ class CommandCSSetMisc : public Command void Execute(CommandSource &source, const std::vector ¶ms) anope_override { ChannelInfo *ci = ChannelInfo::Find(params[0]); + const Anope::string ¶m = params.size() > 1 ? params[1] : ""; if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); @@ -108,7 +109,7 @@ class CommandCSSetMisc : public Command } EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, params[1])); + FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, param)); if (MOD_RESULT == EVENT_STOP) return; @@ -124,9 +125,9 @@ class CommandCSSetMisc : public Command if (item == NULL) return; - if (params.size() > 1) + if (!param.empty()) { - item->Set(ci, CSMiscData(ci, key, params[1])); + item->Set(ci, CSMiscData(ci, key, param)); source.Reply(CHAN_SETTING_CHANGED, scommand.c_str(), ci->name.c_str(), params[1].c_str()); } else diff --git a/modules/commands/os_chankill.cpp b/modules/commands/os_chankill.cpp index 1304dd75c..76a1826da 100644 --- a/modules/commands/os_chankill.cpp +++ b/modules/commands/os_chankill.cpp @@ -69,7 +69,7 @@ class CommandOSChanKill : public Command if ((c = Channel::Find(channel))) { - for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ) + for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) { ChanUserContainer *uc = it->second;