From 14a092a3369fefb3657237a2828b99d4f7845a20 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Wed, 2 Oct 2013 16:05:15 +0200 Subject: [PATCH] ws2_32: Always clear res on error in getaddrinfo/GetAddrInfoW. --- dlls/ws2_32/socket.c | 8 ++++---- dlls/ws2_32/tests/sock.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index bd5a476e804..a14f6244941 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -5397,6 +5397,7 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr char *hostname = NULL; const char *node; + *res = NULL; if (!nodename && !servname) return WSAHOST_NOT_FOUND; if (!nodename) @@ -5479,16 +5480,14 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr xuai = xuai->ai_next; } freeaddrinfo(unixaires); - } else { + } else result = convert_eai_u2w(result); - *res = NULL; - } + return result; outofmem: if (*res) WS_freeaddrinfo(*res); if (unixaires) freeaddrinfo(unixaires); - *res = NULL; return WSA_NOT_ENOUGH_MEMORY; #else FIXME("getaddrinfo() failed, not found during buildtime.\n"); @@ -5595,6 +5594,7 @@ int WINAPI GetAddrInfoW(LPCWSTR nodename, LPCWSTR servname, const ADDRINFOW *hin char *nodenameA = NULL, *servnameA = NULL; struct WS_addrinfo *resA, *hintsA = NULL; + *res = NULL; if (nodename) { len = WideCharToMultiByte(CP_ACP, 0, nodename, -1, NULL, 0, NULL, NULL); diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index fddb820d212..a4c94312f12 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -5092,6 +5092,8 @@ static void test_GetAddrInfoW(void) static const WCHAR port[] = {'8','0',0}; static const WCHAR empty[] = {0}; static const WCHAR localhost[] = {'l','o','c','a','l','h','o','s','t',0}; + static const WCHAR nxdomain[] = + {'n','x','d','o','m','a','i','n','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m',0}; static const WCHAR zero[] = {'0',0}; int ret; ADDRINFOW *result, hint; @@ -5103,8 +5105,10 @@ static void test_GetAddrInfoW(void) } memset(&hint, 0, sizeof(ADDRINFOW)); + result = (ADDRINFOW *)0xdeadbeef; ret = pGetAddrInfoW(NULL, NULL, NULL, &result); ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret); + ok(result == NULL, "got %p\n", result); result = NULL; ret = pGetAddrInfoW(empty, NULL, NULL, &result); @@ -5144,10 +5148,25 @@ static void test_GetAddrInfoW(void) ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError()); pFreeAddrInfoW(result); + result = NULL; + ret = pGetAddrInfoW(localhost, NULL, &hint, &result); + ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError()); + pFreeAddrInfoW(result); + result = NULL; ret = pGetAddrInfoW(localhost, port, &hint, &result); ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError()); pFreeAddrInfoW(result); + + result = (ADDRINFOW *)0xdeadbeef; + ret = pGetAddrInfoW(NULL, NULL, NULL, &result); + ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret); + ok(result == NULL, "got %p\n", result); + + result = (ADDRINFOW *)0xdeadbeef; + ret = pGetAddrInfoW(nxdomain, NULL, NULL, &result); + ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret); + ok(result == NULL, "got %p\n", result); } static void test_getaddrinfo(void) @@ -5162,8 +5181,10 @@ static void test_getaddrinfo(void) } memset(&hint, 0, sizeof(ADDRINFOA)); + result = (ADDRINFOA *)0xdeadbeef; ret = pgetaddrinfo(NULL, NULL, NULL, &result); ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret); + ok(result == NULL, "got %p\n", result); result = NULL; ret = pgetaddrinfo("", NULL, NULL, &result); @@ -5203,10 +5224,20 @@ static void test_getaddrinfo(void) ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError()); pfreeaddrinfo(result); + result = NULL; + ret = pgetaddrinfo("localhost", NULL, &hint, &result); + ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError()); + pfreeaddrinfo(result); + result = NULL; ret = pgetaddrinfo("localhost", "80", &hint, &result); ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError()); pfreeaddrinfo(result); + + result = (ADDRINFOA *)0xdeadbeef; + ret = pgetaddrinfo("nxdomain.codeweavers.com", NULL, NULL, &result); + ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret); + ok(result == NULL, "got %p\n", result); } static void test_ConnectEx(void)