diff options
-rw-r--r-- | src/modules.cpp | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/src/modules.cpp b/src/modules.cpp index 9deaa7954..00d7e7871 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -509,27 +509,30 @@ bool InspIRCd::DelELine(const std::string &hostmask) bool InspIRCd::IsValidMask(const std::string &mask) { char* dest = (char*)mask.c_str(); - if (strchr(dest,'!')==0) - return false; - if (strchr(dest,'@')==0) - return false; - for (char* i = dest; *i; i++) - if (*i < 32) - return false; + int exclamation = 0; + int atsign = 0; + for (char* i = dest; *i; i++) - if (*i > 126) + { + /* out of range character, bad mask */ + if (*i < 32 || *i > 126) + { return false; - unsigned int c = 0; - for (char* i = dest; *i; i++) - if (*i == '!') - c++; - if (c>1) - return false; - c = 0; - for (char* i = dest; *i; i++) - if (*i == '@') - c++; - if (c>1) + } + + switch (*i) + { + case '!': + exclamation++; + break; + case '@': + atsign++; + break; + } + } + + /* valid masks only have 1 ! and @ */ + if (exclamation != 1 || atsign != 1) return false; return true; |