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
--- 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;