From e5f7fee279b03e0d122c96b6b45758f5eede7ab2 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 13 Jul 2017 15:41:21 +0200 Subject: [PATCH] Fix #1664 CIDR IP --- .../java/org/eclipse/jetty/util/InetAddressSet.java | 4 ++-- .../org/eclipse/jetty/util/InetAddressSetTest.java | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/InetAddressSet.java b/jetty-util/src/main/java/org/eclipse/jetty/util/InetAddressSet.java index 0c616878fbf..c42f2a3ea33 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/InetAddressSet.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/InetAddressSet.java @@ -246,11 +246,11 @@ public class InetAddressSet extends AbstractSet implements Set, _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++) diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/InetAddressSetTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/InetAddressSetTest.java index c52585291c0..14c650980ea 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/InetAddressSetTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/InetAddressSetTest.java @@ -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 {