Commit 06901e4a authored by Eric Roman's avatar Eric Roman Committed by Commit Bot

Accept IPv4 mapped IPv6 literals from PAC's isInNetEx() function.

Bug: 997372
Change-Id: Ia8f870bd9afe93c156a24271f2751c70d4972f63
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1769726
Commit-Queue: Eric Roman <eroman@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690447}
parent 19da2cde
......@@ -189,10 +189,25 @@ Tests.testIsInNetEx = function(t) {
t.expectTrue(isInNetEx("3ffe:8311:ffff:abcd:1234:dead:beef:101",
"3ffe:8311:ffff::/48"));
// IPv4 and IPv6 mix.
t.expectFalse(isInNetEx("127.0.0.1", "0:0:0:0:0:0:7f00:1/16"));
// Test an IPv4 literal against an IPv6 range. This passes since 127.0.0.1 is
// ::ffff:127.0.0.1 in IPv4 mapped notation.
t.expectTrue(isInNetEx("127.0.0.1", "0:0:0:0:0:0:7f00:1/16"));
// Test an IPv4 literal against an IPv6 range. Doesn't match when
// 192.168.24.3 is mapped to IPv6.
t.expectFalse(isInNetEx("192.168.24.3", "fe80:0:0:0:0:0:c0a8:1803/32"));
// Test that IPv4 ranges work interchangeably with IPv4 mapped IPv6 literals
// - both for the range prefix and the test address.
t.expectTrue(isInNetEx("::ffff:192.168.100.5", "192.168.1.1/16"));
t.expectFalse(isInNetEx("::ffff:10.168.100.5", "192.168.1.1/16"));
t.expectFalse(isInNetEx("::fffe:192.168.100.5", "192.168.1.1/16"));
t.expectTrue(isInNetEx("::ffff:192.168.100.5", "::ffff:192.168.1.1/112"));
t.expectFalse(isInNetEx("::ffff:10.168.100.5", "::ffff:192.168.1.1/112"));
t.expectTrue(isInNetEx("192.168.1.1", "::ffff:192.168.1.1/112"));
t.expectFalse(isInNetEx("192.168.1.1", "::fffe:192.168.1.1/112"));
t.expectFalse(isInNetEx("10.168.1.1", "::ffff:192.168.1.1/112"));
t.expectFalse(isInNetEx("198.95.249.78", "198.95.249.79/32"));
t.expectFalse(isInNetEx("198.96.115.10", "198.95.0.0/16"));
t.expectFalse(isInNetEx("3fff:8311:ffff:abcd:1234:dead:beef:101",
......
......@@ -322,8 +322,9 @@ bool SortIpAddressList(const std::string& ip_address_list,
// slash-delimited IP prefix with the top 'n' bits specified in the bit
// field. This returns 'true' if the address is in the same subnet, and
// 'false' otherwise. Also returns 'false' if the prefix is in an incorrect
// format, or if an address and prefix of different types are used (e.g. IPv6
// address and IPv4 prefix).
// format. If the address types of |ip_address| and |ip_prefix| don't match,
// will promote the IPv4 literal to an IPv4 mapped IPv6 literal and
// proceed with the comparison.
bool IsInNetEx(const std::string& ip_address, const std::string& ip_prefix) {
IPAddress address;
if (!address.AssignFromIPLiteral(ip_address))
......@@ -334,13 +335,6 @@ bool IsInNetEx(const std::string& ip_address, const std::string& ip_prefix) {
if (!ParseCIDRBlock(ip_prefix, &prefix, &prefix_length_in_bits))
return false;
// Both |address| and |prefix| must be of the same type (IPv4 or IPv6).
if (address.size() != prefix.size())
return false;
DCHECK((address.IsIPv4() && prefix.IsIPv4()) ||
(address.IsIPv6() && prefix.IsIPv6()));
return IPAddressMatchesPrefix(address, prefix, prefix_length_in_bits);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment