8019834: InetAddress.getByName hangs for bad IPv6 literals
authorchegar
Fri, 08 Nov 2013 15:15:48 +0000
changeset 21630 58a025b37bff
parent 21629 c347092074d9
child 21631 73fa744f1283
8019834: InetAddress.getByName hangs for bad IPv6 literals Reviewed-by: alanb
jdk/src/share/classes/java/net/InetAddress.java
jdk/test/java/net/ipv6tests/BadIPv6Addresses.java
--- a/jdk/src/share/classes/java/net/InetAddress.java	Fri Nov 08 15:12:30 2013 +0000
+++ b/jdk/src/share/classes/java/net/InetAddress.java	Fri Nov 08 15:15:48 2013 +0000
@@ -1135,7 +1135,7 @@
             // see if it is IPv4 address
             addr = IPAddressUtil.textToNumericFormatV4(host);
             if (addr == null) {
-                // see if it is IPv6 address
+                // This is supposed to be an IPv6 literal
                 // Check if a numeric or string zone id is present
                 int pos;
                 if ((pos=host.indexOf ("%")) != -1) {
@@ -1144,7 +1144,9 @@
                         ifname = host.substring (pos+1);
                     }
                 }
-                addr = IPAddressUtil.textToNumericFormatV6(host);
+                if ((addr = IPAddressUtil.textToNumericFormatV6(host)) == null) {
+                    throw new UnknownHostException(host + ": invalid IPv6 address");
+                }
             } else if (ipv6Expected) {
                 // Means an IPv4 litteral between brackets!
                 throw new UnknownHostException("["+host+"]");
@@ -1162,10 +1164,10 @@
                 }
                 return ret;
             }
-            } else if (ipv6Expected) {
-                // We were expecting an IPv6 Litteral, but got something else
-                throw new UnknownHostException("["+host+"]");
-            }
+        } else if (ipv6Expected) {
+            // We were expecting an IPv6 Litteral, but got something else
+            throw new UnknownHostException("["+host+"]");
+        }
         return getAllByName0(host, reqAddr, true);
     }
 
--- a/jdk/test/java/net/ipv6tests/BadIPv6Addresses.java	Fri Nov 08 15:12:30 2013 +0000
+++ b/jdk/test/java/net/ipv6tests/BadIPv6Addresses.java	Fri Nov 08 15:15:48 2013 +0000
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 4742177
+ * @bug 4742177 8019834
  * @summary Re-test IPv6 (and specifically MulticastSocket) with latest Linux & USAGI code
  */
 import java.net.*;