diff options
author | Adam <Adam@anope.org> | 2013-12-26 17:30:49 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2013-12-26 17:33:06 -0500 |
commit | b28db7bc551bd011f05d39328ec95c39df065fcd (patch) | |
tree | 600bc15babdccacab492beb2c8056ce8b799dbc9 /modules/commands/bs_kick.cpp | |
parent | 9bf9cfcf5e122f9f46ad096b9f979a95c10d2d4b (diff) |
Fix crash with badwords of type 'end' and possibly when messages contain only control codes. Also fix matching single words at the beginning of lines.
Diffstat (limited to 'modules/commands/bs_kick.cpp')
-rw-r--r-- | modules/commands/bs_kick.cpp | 102 |
1 files changed, 55 insertions, 47 deletions
diff --git a/modules/commands/bs_kick.cpp b/modules/commands/bs_kick.cpp index 4c1b1eb0c..26a5466d0 100644 --- a/modules/commands/bs_kick.cpp +++ b/modules/commands/bs_kick.cpp @@ -1324,73 +1324,81 @@ class BSKick : public Module Anope::string nbuf = Anope::NormalizeBuffer(realbuf); bool casesensitive = Config->GetModule("botserv")->Get<bool>("casesensitive"); - for (unsigned i = 0; badwords && i < badwords->GetBadWordCount(); ++i) - { - const BadWord *bw = badwords->GetBadWord(i); - - if (bw->type == BW_ANY && ((casesensitive && nbuf.find(bw->word) != Anope::string::npos) || (!casesensitive && nbuf.find_ci(bw->word) != Anope::string::npos))) - mustkick = true; - else if (bw->type == BW_SINGLE) + /* Normalize can return an empty string if this only conains control codes etc */ + if (badwords && !nbuf.empty()) + for (unsigned i = 0; i < badwords->GetBadWordCount(); ++i) { - size_t len = bw->word.length(); + const BadWord *bw = badwords->GetBadWord(i); - if ((casesensitive && bw->word.equals_cs(nbuf)) || (!casesensitive && bw->word.equals_ci(nbuf))) - mustkick = true; - else if (nbuf.find(' ') == len && ((casesensitive && bw->word.equals_cs(nbuf)) || (!casesensitive && bw->word.equals_ci(nbuf)))) + if (bw->word.empty()) + continue; // Shouldn't happen + + if (bw->word.length() > nbuf.length()) + continue; // This can't ever match + + if (bw->type == BW_ANY && ((casesensitive && nbuf.find(bw->word) != Anope::string::npos) || (!casesensitive && nbuf.find_ci(bw->word) != Anope::string::npos))) mustkick = true; - else + else if (bw->type == BW_SINGLE) { - if (nbuf.rfind(' ') == nbuf.length() - len - 1 && ((casesensitive && nbuf.find(bw->word) == nbuf.length() - len) || (!casesensitive && nbuf.find_ci(bw->word) == nbuf.length() - len))) + size_t len = bw->word.length(); + + if ((casesensitive && bw->word.equals_cs(nbuf)) || (!casesensitive && bw->word.equals_ci(nbuf))) + mustkick = true; + else if (nbuf.find(' ') == len && ((casesensitive && bw->word.equals_cs(nbuf.substr(0, len))) || (!casesensitive && bw->word.equals_ci(nbuf.substr(0, len))))) mustkick = true; else { - Anope::string wordbuf = " " + bw->word + " "; - - if ((casesensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!casesensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) + if (len < nbuf.length() && nbuf.rfind(' ') == nbuf.length() - len - 1 && ((casesensitive && nbuf.find(bw->word) == nbuf.length() - len) || (!casesensitive && nbuf.find_ci(bw->word) == nbuf.length() - len))) mustkick = true; + else + { + Anope::string wordbuf = " " + bw->word + " "; + + if ((casesensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!casesensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) + mustkick = true; + } } } - } - else if (bw->type == BW_START) - { - size_t len = bw->word.length(); - - if ((casesensitive && nbuf.substr(0, len).equals_cs(bw->word)) || (!casesensitive && nbuf.substr(0, len).equals_ci(bw->word))) - mustkick = true; - else + else if (bw->type == BW_START) { - Anope::string wordbuf = " " + bw->word; + size_t len = bw->word.length(); - if ((casesensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!casesensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) + if ((casesensitive && nbuf.substr(0, len).equals_cs(bw->word)) || (!casesensitive && nbuf.substr(0, len).equals_ci(bw->word))) mustkick = true; - } - } - else if (bw->type == BW_END) - { - size_t len = bw->word.length(); + else + { + Anope::string wordbuf = " " + bw->word; - if ((casesensitive && nbuf.substr(nbuf.length() - len).equals_cs(bw->word)) || (!casesensitive && nbuf.substr(nbuf.length() - len).equals_ci(bw->word))) - mustkick = true; - else + if ((casesensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!casesensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) + mustkick = true; + } + } + else if (bw->type == BW_END) { - Anope::string wordbuf = bw->word + " "; + size_t len = bw->word.length(); - if ((casesensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!casesensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) + if ((casesensitive && nbuf.substr(nbuf.length() - len).equals_cs(bw->word)) || (!casesensitive && nbuf.substr(nbuf.length() - len).equals_ci(bw->word))) mustkick = true; + else + { + Anope::string wordbuf = bw->word + " "; + + if ((casesensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!casesensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) + mustkick = true; + } } - } - if (mustkick) - { - check_ban(ci, u, kd, TTB_BADWORDS); - if (Config->GetModule(me)->Get<bool>("gentlebadwordreason")) - bot_kick(ci, u, _("Watch your language!")); - else - bot_kick(ci, u, _("Don't use the word \"%s\" on this channel!"), bw->word.c_str()); + if (mustkick) + { + check_ban(ci, u, kd, TTB_BADWORDS); + if (Config->GetModule(me)->Get<bool>("gentlebadwordreason")) + bot_kick(ci, u, _("Watch your language!")); + else + bot_kick(ci, u, _("Don't use the word \"%s\" on this channel!"), bw->word.c_str()); - return; - } - } /* for */ + return; + } + } /* for */ } /* if badwords */ UserData *ud = GetUserData(u, c); |