Fix #1664 CIDR IP
This commit is contained in:
parent
6244d0df3c
commit
7b1d4c7ccf
|
@ -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++)
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue