diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/cmd_nick.cpp | 2 | ||||
-rw-r--r-- | src/configreader.cpp | 2 | ||||
-rw-r--r-- | src/helperfuncs.cpp | 41 | ||||
-rw-r--r-- | src/modules/m_channames.cpp | 29 | ||||
-rw-r--r-- | src/modules/m_nationalchars.cpp | 13 | ||||
-rw-r--r-- | src/modules/m_nicklock.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_sanick.cpp | 2 |
7 files changed, 39 insertions, 52 deletions
diff --git a/src/commands/cmd_nick.cpp b/src/commands/cmd_nick.cpp index a079e59d0..4c26d947f 100644 --- a/src/commands/cmd_nick.cpp +++ b/src/commands/cmd_nick.cpp @@ -66,7 +66,7 @@ CmdResult CommandNick::Handle (const std::vector<std::string>& parameters, User { newnick = user->uuid; } - else if (!ServerInstance->IsNick(newnick.c_str(), ServerInstance->Config->Limits.NickMax)) + else if (!ServerInstance->IsNick(newnick, ServerInstance->Config->Limits.NickMax)) { user->WriteNumeric(432, "%s %s :Erroneous Nickname", user->nick.c_str(),newnick.c_str()); return CMD_FAILURE; diff --git a/src/configreader.cpp b/src/configreader.cpp index df78fcab8..668290f4d 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -241,7 +241,7 @@ void ServerConfig::CrossCheckOperClassType() std::string name = tag->getString("name"); if (name.empty()) throw CoreException("<type:name> is missing from tag at " + tag->getTagLocation()); - if (!ServerInstance->IsNick(name.c_str(), Limits.NickMax)) + if (!ServerInstance->IsNick(name, Limits.NickMax)) throw CoreException("<type:name> is invalid (value '" + name + "')"); if (oper_blocks.find(" " + name) != oper_blocks.end()) throw CoreException("Duplicate type block with name " + name + " at " + tag->getTagLocation()); diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 7ee78c46e..42cb55cfd 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -281,47 +281,35 @@ void InspIRCd::ProcessColors(file_cache& input) } /* true for valid channel name, false else */ -bool IsChannelHandler::Call(const char *chname, size_t max) +bool IsChannelHandler::Call(const std::string& chname, size_t max) { - const char *c = chname + 1; + if (chname.empty() || chname.length() > max) + return false; - /* check for no name - don't check for !*chname, as if it is empty, it won't be '#'! */ - if (!chname || *chname != '#') - { + if (chname[0] != '#') return false; - } - while (*c) + for (std::string::const_iterator i = chname.begin()+1; i != chname.end(); ++i) { - switch (*c) + switch (*i) { case ' ': case ',': case 7: return false; } - - c++; - } - - size_t len = c - chname; - /* too long a name - note funky pointer arithmetic here. */ - if (len > max) - { - return false; } return true; } /* true for valid nickname, false else */ -bool IsNickHandler::Call(const char* n, size_t max) +bool IsNickHandler::Call(const std::string& n, size_t max) { - if (!n || !*n) + if (n.empty() || n.length() > max) return false; - unsigned int p = 0; - for (const char* i = n; *i; i++, p++) + for (std::string::const_iterator i = n.begin(); i != n.end(); ++i) { if ((*i >= 'A') && (*i <= '}')) { @@ -329,7 +317,7 @@ bool IsNickHandler::Call(const char* n, size_t max) continue; } - if ((((*i >= '0') && (*i <= '9')) || (*i == '-')) && (i > n)) + if ((((*i >= '0') && (*i <= '9')) || (*i == '-')) && (i != n.begin())) { /* "0"-"9", "-" can occur anywhere BUT the first char of a nickname */ continue; @@ -339,17 +327,16 @@ bool IsNickHandler::Call(const char* n, size_t max) return false; } - /* too long? or not */ - return (p <= max); + return true; } /* return true for good ident, false else */ -bool IsIdentHandler::Call(const char* n) +bool IsIdentHandler::Call(const std::string& n) { - if (!n || !*n) + if (n.empty()) return false; - for (const char* i = n; *i; i++) + for (std::string::const_iterator i = n.begin(); i != n.end(); ++i) { if ((*i >= 'A') && (*i <= '}')) { diff --git a/src/modules/m_channames.cpp b/src/modules/m_channames.cpp index e78171c4a..e9e5ba305 100644 --- a/src/modules/m_channames.cpp +++ b/src/modules/m_channames.cpp @@ -23,35 +23,34 @@ static std::bitset<256> allowedmap; -class NewIsChannelHandler : public HandlerBase2<bool, const char*, size_t> +class NewIsChannelHandler : public HandlerBase2<bool, const std::string&, size_t> { public: NewIsChannelHandler() { } virtual ~NewIsChannelHandler() { } - virtual bool Call(const char*, size_t); + virtual bool Call(const std::string&, size_t); }; -bool NewIsChannelHandler::Call(const char* c, size_t max) +bool NewIsChannelHandler::Call(const std::string& channame, size_t max) { - /* check for no name - don't check for !*chname, as if it is empty, it won't be '#'! */ - if (!c || *c++ != '#') + if (channame.empty() || channame.length() > max || channame[0] != '#') + return false; + + for (std::string::const_iterator c = channame.begin(); c != channame.end(); ++c) + { + unsigned int i = *c & 0xFF; + if (!allowedmap[i]) return false; + } - while (*c && --max) - { - unsigned int i = *c++ & 0xFF; - if (!allowedmap[i]) - return false; - } - // a name of exactly max length will have max = 1 here; the null does not trigger --max - return max; + return true; } class ModuleChannelNames : public Module { private: NewIsChannelHandler myhandler; - caller2<bool, const char*, size_t> rememberer; + caller2<bool, const std::string&, size_t> rememberer; bool badchan; public: @@ -73,7 +72,7 @@ class ModuleChannelNames : public Module std::vector<Channel*> chanvec; for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); ++i) { - if (!ServerInstance->IsChannel(i->second->name.c_str(), MAXBUF)) + if (!ServerInstance->IsChannel(i->second->name, MAXBUF)) chanvec.push_back(i->second); } std::vector<Channel*>::reverse_iterator c2 = chanvec.rbegin(); diff --git a/src/modules/m_nationalchars.cpp b/src/modules/m_nationalchars.cpp index b43b6e2b6..59277bb9e 100644 --- a/src/modules/m_nationalchars.cpp +++ b/src/modules/m_nationalchars.cpp @@ -31,12 +31,12 @@ /* $ModDesc: Provides an ability to have non-RFC1459 nicks & support for national CASEMAPPING */ -class lwbNickHandler : public HandlerBase2<bool, const char*, size_t> +class lwbNickHandler : public HandlerBase2<bool, const std::string&, size_t> { public: lwbNickHandler() { } virtual ~lwbNickHandler() { } - virtual bool Call(const char*, size_t); + virtual bool Call(const std::string&, size_t); }; /*,m_reverse_additionalUp[256];*/ @@ -71,11 +71,12 @@ char utf8size(unsigned char * mb) /* Conditions added */ -bool lwbNickHandler::Call(const char* n, size_t max) +bool lwbNickHandler::Call(const std::string& nick, size_t max) { - if (!n || !*n) + if (nick.empty()) return false; + const char* n = nick.c_str(); unsigned int p = 0; for (const char* i = n; *i; i++, p++) { @@ -225,7 +226,7 @@ class ModuleNationalChars : public Module lwbNickHandler myhandler; std::string charset, casemapping; unsigned char m_additional[256], m_additionalUp[256], m_lower[256], m_upper[256]; - caller2<bool, const char*, size_t> rememberer; + caller2<bool, const std::string&, size_t> rememberer; bool forcequit; const unsigned char * lowermap_rememberer; @@ -276,7 +277,7 @@ class ModuleNationalChars : public Module { /* Fix by Brain: Dont quit UID users */ User* n = *iter; - if (!isdigit(n->nick[0]) && !ServerInstance->IsNick(n->nick.c_str(), ServerInstance->Config->Limits.NickMax)) + if (!isdigit(n->nick[0]) && !ServerInstance->IsNick(n->nick, ServerInstance->Config->Limits.NickMax)) ServerInstance->Users->QuitUser(n, message); } } diff --git a/src/modules/m_nicklock.cpp b/src/modules/m_nicklock.cpp index abeb25869..b5564f215 100644 --- a/src/modules/m_nicklock.cpp +++ b/src/modules/m_nicklock.cpp @@ -51,7 +51,7 @@ class CommandNicklock : public Command /* Do local sanity checks and bails */ if (IS_LOCAL(user)) { - if (!ServerInstance->IsNick(parameters[1].c_str(), ServerInstance->Config->Limits.NickMax)) + if (!ServerInstance->IsNick(parameters[1], ServerInstance->Config->Limits.NickMax)) { user->WriteServ("NOTICE %s :*** Invalid nickname '%s'", user->nick.c_str(), parameters[1].c_str()); return CMD_FAILURE; diff --git a/src/modules/m_sanick.cpp b/src/modules/m_sanick.cpp index 4e4be77ae..ba4fdc033 100644 --- a/src/modules/m_sanick.cpp +++ b/src/modules/m_sanick.cpp @@ -54,7 +54,7 @@ class CommandSanick : public Command return CMD_FAILURE; } - if (!ServerInstance->IsNick(parameters[1].c_str(), ServerInstance->Config->Limits.NickMax)) + if (!ServerInstance->IsNick(parameters[1], ServerInstance->Config->Limits.NickMax)) { user->WriteServ("NOTICE %s :*** Invalid nickname '%s'", user->nick.c_str(), parameters[1].c_str()); return CMD_FAILURE; |