Module: wine Branch: master Commit: 14a092a3369fefb3657237a2828b99d4f7845a20 URL: http://source.winehq.org/git/wine.git/?a=commit;h=14a092a3369fefb3657237a282...
Author: Hans Leidekker hans@codeweavers.com Date: Wed Oct 2 16:05:15 2013 +0200
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 bd5a476..a14f624 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 fddb820..a4c94312 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); @@ -5145,9 +5149,24 @@ static void test_GetAddrInfoW(void) 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); @@ -5204,9 +5225,19 @@ static void test_getaddrinfo(void) 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)