8026806: Incomplete test of getaddrinfo() return value could lead to incorrect exception for Windows Inet 6
authorbpb
Tue, 22 Oct 2013 10:44:22 -0700
changeset 21325 8ccf86fcccda
parent 21324 1f9eb351241e
child 21326 6abd31ba3aba
8026806: Incomplete test of getaddrinfo() return value could lead to incorrect exception for Windows Inet 6 Summary: Check getaddrinfo return value before calling WSAGetLastError. Reviewed-by: alanb, dsamersoff
jdk/src/windows/native/java/net/Inet6AddressImpl.c
--- a/jdk/src/windows/native/java/net/Inet6AddressImpl.c	Tue Oct 22 14:13:06 2013 +0100
+++ b/jdk/src/windows/native/java/net/Inet6AddressImpl.c	Tue Oct 22 10:44:22 2013 -0700
@@ -131,18 +131,20 @@
 
     error = getaddrinfo(hostname, NULL, &hints, &res);
 
-    if (WSAGetLastError() == WSATRY_AGAIN) {
-        NET_ThrowByNameWithLastError(env,
-                                     JNU_JAVANETPKG "UnknownHostException",
-                                     hostname);
-        JNU_ReleaseStringPlatformChars(env, host, hostname);
-        return NULL;
-    } else if (error) {
-        /* report error */
-        JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException",
-                        (char *)hostname);
-        JNU_ReleaseStringPlatformChars(env, host, hostname);
-        return NULL;
+    if (error) {
+        if (WSAGetLastError() == WSATRY_AGAIN) {
+            NET_ThrowByNameWithLastError(env,
+                                         JNU_JAVANETPKG "UnknownHostException",
+                                         hostname);
+            JNU_ReleaseStringPlatformChars(env, host, hostname);
+            return NULL;
+        } else {
+            /* report error */
+            JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException",
+                            (char *)hostname);
+            JNU_ReleaseStringPlatformChars(env, host, hostname);
+            return NULL;
+        }
     } else {
         int i = 0;
         int inetCount = 0, inet6Count = 0, inetIndex, inet6Index;