From da3bdef026ee6b1ccc173a19e3f542dc0284fcbb Mon Sep 17 00:00:00 2001 From: bpb Date: Tue, 22 Oct 2013 10:44:22 -0700 Subject: [PATCH] 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 --- .../native/java/net/Inet6AddressImpl.c | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/windows/native/java/net/Inet6AddressImpl.c b/src/windows/native/java/net/Inet6AddressImpl.c index 0e6fc308a..4531402bb 100644 --- a/src/windows/native/java/net/Inet6AddressImpl.c +++ b/src/windows/native/java/net/Inet6AddressImpl.c @@ -131,18 +131,20 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, 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; -- GitLab