changeset 7240:184171631add

8019834: InetAddress.getByName hangs for bad IPv6 literals Reviewed-by: alanb
author igerasim
date Wed, 18 Jun 2014 14:40:16 +0400
parents 9df69ec6c161
children 488d331ecd1e
files src/share/classes/java/net/InetAddress.java test/java/net/ipv6tests/BadIPv6Addresses.java
diffstat 2 files changed, 9 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/net/InetAddress.java	Wed Jun 18 14:11:38 2014 +0400
+++ b/src/share/classes/java/net/InetAddress.java	Wed Jun 18 14:40:16 2014 +0400
@@ -1128,7 +1128,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) {
@@ -1137,7 +1137,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+"]");
@@ -1155,10 +1157,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/test/java/net/ipv6tests/BadIPv6Addresses.java	Wed Jun 18 14:11:38 2014 +0400
+++ b/test/java/net/ipv6tests/BadIPv6Addresses.java	Wed Jun 18 14:40:16 2014 +0400
@@ -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.*;