]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add ModeParser::IsModeChar to standardise mode validation.
authorPeter Powell <petpow@saberuk.com>
Mon, 11 Sep 2017 14:22:40 +0000 (15:22 +0100)
committerPeter Powell <petpow@saberuk.com>
Mon, 18 Sep 2017 13:09:01 +0000 (14:09 +0100)
include/mode.h
src/configreader.cpp
src/mode.cpp

index 2aa781c28874dc5bb32658aca442c0c8c2d84ae4..6b481e7796c744a2efbf2e5055401b2899d9c25c 100644 (file)
@@ -630,6 +630,8 @@ class CoreExport ModeParser : public fakederef<ModeParser>
         */
        static void InitBuiltinModes();
 
+       static bool IsModeChar(char chr);
+
        /** Tidy a banmask. This makes a banmask 'acceptable' if fields are left out.
         * E.g.
         *
index cc478b9b6be1986e126b20363c8ce541fe369c30..005730dca12987a6f1a4890c231b03d68df5c0ea 100644 (file)
@@ -487,8 +487,8 @@ void ServerConfig::Fill()
        std::string modes = ConfValue("disabled")->getString("usermodes");
        for (std::string::const_iterator p = modes.begin(); p != modes.end(); ++p)
        {
-               // Complain when the character is not a-z or A-Z
-               if ((*p < 'A') || (*p > 'z') || ((*p < 'a') && (*p > 'Z')))
+               // Complain when the character is not a valid mode character.
+               if (!ModeParser::IsModeChar(*p))
                        throw CoreException("Invalid usermode " + std::string(1, *p) + " was found.");
                DisabledUModes[*p - 'A'] = 1;
        }
@@ -497,7 +497,7 @@ void ServerConfig::Fill()
        modes = ConfValue("disabled")->getString("chanmodes");
        for (std::string::const_iterator p = modes.begin(); p != modes.end(); ++p)
        {
-               if ((*p < 'A') || (*p > 'z') || ((*p < 'a') && (*p > 'Z')))
+               if (!ModeParser::IsModeChar(*p))
                        throw CoreException("Invalid chanmode " + std::string(1, *p) + " was found.");
                DisabledCModes[*p - 'A'] = 1;
        }
index 22173c189aa63ee5dcc63870f2cecbfb0d5464a9..cd825d7a292b16e8ffb91be6c5566ac43d98e0cc 100644 (file)
@@ -570,11 +570,7 @@ ModeHandler::Id ModeParser::AllocateModeId(ModeType mt)
 
 void ModeParser::AddMode(ModeHandler* mh)
 {
-       /* Yes, i know, this might let people declare modes like '_' or '^'.
-        * If they do that, thats their problem, and if i ever EVER see an
-        * official InspIRCd developer do that, i'll beat them with a paddle!
-        */
-       if ((mh->GetModeChar() < 'A') || (mh->GetModeChar() > 'z'))
+       if (!ModeParser::IsModeChar(mh->GetModeChar()))
                throw ModuleException("Invalid letter for mode " + mh->name);
 
        /* A mode prefix of ',' is not acceptable, it would fuck up server to server.
@@ -624,7 +620,7 @@ void ModeParser::AddMode(ModeHandler* mh)
 
 bool ModeParser::DelMode(ModeHandler* mh)
 {
-       if ((mh->GetModeChar() < 'A') || (mh->GetModeChar() > 'z'))
+       if (!ModeParser::IsModeChar(mh->GetModeChar()))
                return false;
 
        ModeHandlerMap& mhmap = modehandlersbyname[mh->GetModeType()];
@@ -694,7 +690,7 @@ ModeHandler* ModeParser::FindMode(const std::string& modename, ModeType mt)
 
 ModeHandler* ModeParser::FindMode(unsigned const char modeletter, ModeType mt)
 {
-       if ((modeletter < 'A') || (modeletter > 'z'))
+       if (!ModeParser::IsModeChar(modeletter))
                return NULL;
 
        return modehandlers[mt][modeletter-65];
@@ -919,6 +915,11 @@ void ModeParser::InitBuiltinModes()
        static_modes.b.DoRehash();
 }
 
+bool ModeParser::IsModeChar(char chr)
+{
+       return ((chr >= 'A' && chr <= 'Z') || (chr >= 'a' && chr <= 'z'));
+}
+
 ModeParser::ModeParser()
 {
        /* Clear mode handler list */