From 15c200c908590e1d9a5233d2cf5e78919a519ef5 Mon Sep 17 00:00:00 2001 From: Donal Cahill Date: Sun, 13 Dec 2015 23:16:58 +0000 Subject: [PATCH] Disallow CIDR /00000 --- src/User.cpp | 11 +---------- test/UserTest.cpp | 2 +- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/User.cpp b/src/User.cpp index 6e424e9c..d73c70e3 100644 --- a/src/User.cpp +++ b/src/User.cpp @@ -864,16 +864,7 @@ bool CUser::IsHostAllowed(const CString& sHostMask) const { // If iRoutingPrefix is 0, it could be due to ToInt() failing, so // sRoutingPrefix needs to be all zeroes - if (iRoutingPrefix == 0) { - bool bBadPrefix = false; - for (const char c : sRoutingPrefix) { - if (c != '0') { - bBadPrefix = true; - break; - } - } - if (bBadPrefix) continue; - } + if (iRoutingPrefix == 0 && !sRoutingPrefix.Equals("0")) continue; // Convert each IP from a numeric string to an addrinfo addrinfo aiHints; diff --git a/test/UserTest.cpp b/test/UserTest.cpp index 8af79f62..bd47b13f 100644 --- a/test/UserTest.cpp +++ b/test/UserTest.cpp @@ -106,7 +106,7 @@ TEST_F(UserTest, IsHostAllowed) { {"127.0.0.1/33", "127.0.0.1", false}, {"::1/129", "::1", false}, - {"::2/00000000000", "::1", true}, + {"::2/00000000000", "::1", false}, {"::2/0a", "::1", false}, };