Add test suites for edge cases and in the process, spot a crash in the new code and fix it (empty mask in the match() functions makes it bomb)

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9682 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
brain 2008-05-09 18:39:37 +00:00
parent 03ef675c0d
commit 8888d8ef07
2 changed files with 13 additions and 0 deletions

View File

@ -121,6 +121,8 @@ bool TestSuite::DoWildTests()
WCTESTNOT("foobar", "*qux");
WCTESTNOT("foobar", "foo*x");
WCTESTNOT("foobar", "baz*");
WCTESTNOT("foobar", "foo???r");
WCTESTNOT("foobar", "");
CIDRTEST("brain@1.2.3.4", "*@1.2.0.0/16");
CIDRTEST("brain@1.2.3.4", "*@1.2.3.0/24");
@ -128,6 +130,11 @@ bool TestSuite::DoWildTests()
CIDRTESTNOT("brain@1.2.3.4", "x*@1.2.0.0/16");
CIDRTESTNOT("brain@1.2.3.4", "*@1.3.4.0/24");
CIDRTESTNOT("brain@1.2.3.4", "*@/24");
CIDRTESTNOT("brain@1.2.3.4", "@1.2.3.4/9");
CIDRTESTNOT("brain@1.2.3.4", "@");
CIDRTESTNOT("brain@1.2.3.4", "");
return passed;
}

View File

@ -35,6 +35,9 @@ CoreExport bool csmatch(const std::string &str, const std::string &mask)
std::string::const_iterator wild = mask.begin();
std::string::const_iterator string = str.begin();
if (mask.empty())
return false;
while ((string != str.end()) && (wild != mask.end()) && (*wild != '*'))
{
if ((*wild != *string) && (*wild != '?'))
@ -81,6 +84,9 @@ CoreExport bool match(const std::string &str, const std::string &mask)
std::string::const_iterator wild = mask.begin();
std::string::const_iterator string = str.begin();
if (mask.empty())
return false;
while ((string != str.end()) && (wild != mask.end()) && (*wild != '*'))
{
if ((lowermap[(unsigned char)*wild] != lowermap[(unsigned char)*string]) && (*wild != '?'))