Author: sebb
Date: Thu Aug  3 15:18:54 2017
New Revision: 1804012

URL: http://svn.apache.org/viewvc?rev=1804012&view=rev
Log:
NET-641 SubnetUtils.SubnetInfo.isInRange("0.0.0.0") returns true for CIDR/31, 32

Modified:
    commons/proper/net/trunk/src/changes/changes.xml
    
commons/proper/net/trunk/src/main/java/org/apache/commons/net/util/SubnetUtils.java
    
commons/proper/net/trunk/src/test/java/org/apache/commons/net/SubnetUtilsTest.java

Modified: commons/proper/net/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/changes/changes.xml?rev=1804012&r1=1804011&r2=1804012&view=diff
==============================================================================
--- commons/proper/net/trunk/src/changes/changes.xml [utf-8] (original)
+++ commons/proper/net/trunk/src/changes/changes.xml [utf-8] Thu Aug  3 
15:18:54 2017
@@ -74,6 +74,9 @@ This is mainly a bug-fix release. See fu
  The examples are not part of the public API, so this does not affect 
compatibility.
 
 ">
+            <action issue="NET-641" type="fix" dev="sebb" due-to="pin_ptr">
+            SubnetUtils.SubnetInfo.isInRange("0.0.0.0") returns true for 
CIDR/31, 32
+            </action>
             <action issue="NET-638" type="add" dev="sebb" due-to="Daniel 
Leong">
             Telnet subnegotiations hard-limited to 512 bytes - allow override
             </action>

Modified: 
commons/proper/net/trunk/src/main/java/org/apache/commons/net/util/SubnetUtils.java
URL: 
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/util/SubnetUtils.java?rev=1804012&r1=1804011&r2=1804012&view=diff
==============================================================================
--- 
commons/proper/net/trunk/src/main/java/org/apache/commons/net/util/SubnetUtils.java
 (original)
+++ 
commons/proper/net/trunk/src/main/java/org/apache/commons/net/util/SubnetUtils.java
 Thu Aug  3 15:18:54 2017
@@ -157,12 +157,17 @@ public class SubnetUtils {
         }
 
         /**
-         *
+         * Returns true if the parameter <code>address</code> is in the
+         * range of usable endpoint addresses for this subnet. This excludes 
the
+         * network and broadcast addresses.
          * @param address the address to check
          * @return true if it is in range
          * @since 3.4 (made public)
          */
         public boolean isInRange(int address) {
+            if (address == 0) { // cannot ever be in range; rejecting now 
avoids problems with CIDR/31,32
+                return false;
+            }
             long addLong = address & UNSIGNED_INT_MASK;
             long lowLong = low() & UNSIGNED_INT_MASK;
             long highLong = high() & UNSIGNED_INT_MASK;

Modified: 
commons/proper/net/trunk/src/test/java/org/apache/commons/net/SubnetUtilsTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/test/java/org/apache/commons/net/SubnetUtilsTest.java?rev=1804012&r1=1804011&r2=1804012&view=diff
==============================================================================
--- 
commons/proper/net/trunk/src/test/java/org/apache/commons/net/SubnetUtilsTest.java
 (original)
+++ 
commons/proper/net/trunk/src/test/java/org/apache/commons/net/SubnetUtilsTest.java
 Thu Aug  3 15:18:54 2017
@@ -368,4 +368,11 @@ public class SubnetUtilsTest extends Tes
         utils.setInclusiveHostCount(false);
         assertTrue(info.isInRange("127.0.0.0"));
     }
+
+    public void testNET641() {
+        assertFalse(new 
SubnetUtils("192.168.1.0/00").getInfo().isInRange("0.0.0.0"));
+        assertFalse(new 
SubnetUtils("192.168.1.0/30").getInfo().isInRange("0.0.0.0"));
+        assertFalse(new 
SubnetUtils("192.168.1.0/31").getInfo().isInRange("0.0.0.0"));
+        assertFalse(new 
SubnetUtils("192.168.1.0/32").getInfo().isInRange("0.0.0.0"));
+    }
 }


Reply via email to