diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cidr.cpp | 6 | ||||
-rw-r--r-- | src/testsuite.cpp | 14 |
2 files changed, 15 insertions, 5 deletions
diff --git a/src/cidr.cpp b/src/cidr.cpp index 90654ee82..0fe7c68ca 100644 --- a/src/cidr.cpp +++ b/src/cidr.cpp @@ -100,6 +100,11 @@ bool irc::sockets::MatchCIDR(const std::string &address, const std::string &cidr cidr_copy = cidr_mask.substr(username_mask_pos + 1); } } + else + { + address_copy.assign(address); + cidr_copy.assign(cidr_mask); + } in_addr address_in4; in_addr mask_in4; @@ -109,6 +114,7 @@ bool irc::sockets::MatchCIDR(const std::string &address, const std::string &cidr if (bits_chars != std::string::npos) { bits = atoi(cidr_copy.substr(bits_chars + 1).c_str()); + cidr_copy.erase(bits_chars, cidr_copy.length() - bits_chars); } else { diff --git a/src/testsuite.cpp b/src/testsuite.cpp index cff6d9b93..1cee7500c 100644 --- a/src/testsuite.cpp +++ b/src/testsuite.cpp @@ -98,14 +98,14 @@ TestSuite::TestSuite(InspIRCd* Instance) : ServerInstance(Instance) } /* Test that x matches y with match() */ -#define WCTEST(x, y) cout << "match(\"" << x << "\",\"" << y "\") " << ((passed = (match(x, y) || passed)) ? " SUCCESS!\n" : " FAILURE\n") +#define WCTEST(x, y) cout << "match(\"" << x << "\",\"" << y "\") " << ((passed = (match(x, y))) ? " SUCCESS!\n" : " FAILURE\n") /* Test that x does not match y with match() */ -#define WCTESTNOT(x, y) cout << "!match(\"" << x << "\",\"" << y "\") " << ((passed = ((!match(x, y)) || passed)) ? " SUCCESS!\n" : " FAILURE\n") +#define WCTESTNOT(x, y) cout << "!match(\"" << x << "\",\"" << y "\") " << ((passed = ((!match(x, y)))) ? " SUCCESS!\n" : " FAILURE\n") /* Test that x matches y with match() and cidr enabled */ -#define CIDRTEST(x, y) cout << "match(\"" << x << "\",\"" << y "\", true) " << ((passed = (match(x, y, true) || passed)) ? " SUCCESS!\n" : " FAILURE\n") +#define CIDRTEST(x, y) cout << "match(\"" << x << "\",\"" << y "\", true) " << ((passed = (match(x, y, true))) ? " SUCCESS!\n" : " FAILURE\n") /* Test that x does not match y with match() and cidr enabled */ -#define CIDRTESTNOT(x, y) cout << "!match(\"" << x << "\",\"" << y "\", true) " << ((passed = ((!match(x, y, true)) || passed)) ? " SUCCESS!\n" : " FAILURE\n") +#define CIDRTESTNOT(x, y) cout << "!match(\"" << x << "\",\"" << y "\", true) " << ((passed = ((!match(x, y, true)))) ? " SUCCESS!\n" : " FAILURE\n") bool TestSuite::DoWildTests() { @@ -127,15 +127,19 @@ bool TestSuite::DoWildTests() CIDRTEST("brain@1.2.3.4", "*@1.2.0.0/16"); CIDRTEST("brain@1.2.3.4", "*@1.2.3.0/24"); + CIDRTEST("192.168.3.97", "192.168.3.0/24"); + CIDRTESTNOT("brain@1.2.3.4", "x*@1.2.0.0/16"); CIDRTESTNOT("brain@1.2.3.4", "*@1.3.4.0/24"); + CIDRTESTNOT("1.2.3.4", "1.2.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; + return true; } bool TestSuite::DoThreadTests() |