changeset 10354:9758edb6976f

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
author bpb
date Tue, 22 Oct 2013 10:44:22 -0700
parents 54869853c06c
children 23b124cbf242
files src/windows/native/java/net/Inet6AddressImpl.c
diffstat 1 files changed, 14 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/windows/native/java/net/Inet6AddressImpl.c	Tue Oct 22 14:13:06 2013 +0100
+++ b/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;