This commit is contained in:
Greg Wilkins 2017-07-13 15:41:21 +02:00 committed by Joakim Erdfelt
parent 2b4494e3f6
commit e5f7fee279
2 changed files with 15 additions and 2 deletions

View File

@ -246,11 +246,11 @@ public class InetAddressSet extends AbstractSet<String> implements Set<String>,
_octets = cidr/8;
_mask = 0xff&(0xff<<(8-cidr%8));
_masked = _mask==0?0:_raw[_octets]&_mask;
if (cidr>(_raw.length*8))
throw new IllegalArgumentException("CIDR too large: "+pattern);
if (_mask!=0 && _raw[_octets]!=_masked)
if (_mask!=0 && (0xff&_raw[_octets])!=_masked)
throw new IllegalArgumentException("CIDR bits non zero: "+pattern);
for (int o=_octets+(_mask==0?0:1);o<_raw.length;o++)

View File

@ -134,8 +134,21 @@ public class InetAddressSetTest
set.add("0.0.0.0/0");
assertTrue(set.test(InetAddress.getByName("10.11.0.0")));
// test #1664
set.add("2.144.0.0/14");
set.add("2.176.0.0/12");
set.add("5.22.0.0/17");
set.add("5.22.192.0/19");
assertTrue(set.test(InetAddress.getByName("2.144.0.1")));
assertTrue(set.test(InetAddress.getByName("2.176.0.1")));
assertTrue(set.test(InetAddress.getByName("5.22.0.1")));
assertTrue(set.test(InetAddress.getByName("5.22.192.1")));
}
@Test
public void testBadCIDR() throws Exception
{