diff --git a/source/common/network/utility.cc b/source/common/network/utility.cc index be6467750f6b..de16b7319b64 100644 --- a/source/common/network/utility.cc +++ b/source/common/network/utility.cc @@ -37,7 +37,7 @@ IpWhiteList::IpWhiteList(const Json::Object& config) { Ipv4Entry white_list_entry; white_list_entry.ipv4_address_ = ntohl(addr.s_addr); - white_list_entry.ipv4_mask_ = ~((1 << (32 - mask)) - 1); + white_list_entry.ipv4_mask_ = ~((1ULL << (32 - mask)) - 1); // Check to make sure applying the mask to the address equals the address. This can prevent // user error. diff --git a/test/common/network/utility_test.cc b/test/common/network/utility_test.cc index 830b2c96583f..9b4226a7d3c1 100644 --- a/test/common/network/utility_test.cc +++ b/test/common/network/utility_test.cc @@ -83,6 +83,28 @@ TEST(IpWhiteListTest, Normal) { EXPECT_FALSE(wl.contains("")); } +TEST(IpWhiteListTest, MatchAny) { + std::string json = R"EOF( + { + "ip_white_list": [ + "0.0.0.0/0" + ] + } + )EOF"; + + Json::ObjectPtr loader = Json::Factory::LoadFromString(json); + IpWhiteList wl(*loader); + + EXPECT_TRUE(wl.contains("192.168.3.3")); + EXPECT_TRUE(wl.contains("192.168.3.0")); + EXPECT_TRUE(wl.contains("192.168.3.255")); + EXPECT_TRUE(wl.contains("192.168.0.0")); + EXPECT_TRUE(wl.contains("192.0.0.0")); + EXPECT_TRUE(wl.contains("1.1.1.1")); + + EXPECT_FALSE(wl.contains("")); +} + TEST(NetworkUtility, NonNumericResolve) { EXPECT_THROW(Utility::resolveTCP("localhost", 80), EnvoyException); }