ws2_32: Fix some edge cases for getaddrinfo in BSD and OSX

Bruno Jesus 00cpxxx at gmail.com
Fri Feb 14 04:44:21 CST 2014


Original patch by David Nadlinger

Related to bug http://bugs.winehq.org/show_bug.cgi?id=29756

May also fix Solaris too.

Tested on PC-BSD and Linux, David tested in OSX.
-------------- next part --------------
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index 7a9440f..1ee73b3 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -5451,7 +5451,7 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
     int   result;
     struct addrinfo unixhints, *punixhints = NULL;
     char *hostname = NULL;
-    const char *node;
+    const char *node, *serv;
 
     *res = NULL;
     if (!nodename && !servname) return WSAHOST_NOT_FOUND;
@@ -5466,6 +5466,14 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
     else
         node = nodename;
 
+    /* servname tweaks required by OSX and BSD kernels */
+    if (!servname)
+        serv = NULL;
+    else if (!servname[0])
+        serv = "0";
+    else
+        serv = servname;
+
     if (hints) {
         punixhints = &unixhints;
 
@@ -5501,7 +5509,7 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
     }
 
     /* getaddrinfo(3) is thread safe, no need to wrap in CS */
-    result = getaddrinfo(node, servname, punixhints, &unixaires);
+    result = getaddrinfo(node, serv, punixhints, &unixaires);
 
     TRACE("%s, %s %p -> %p %d\n", debugstr_a(nodename), debugstr_a(servname), hints, res, result);
     HeapFree(GetProcessHeap(), 0, hostname);
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index cb67533..e146548 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -5402,12 +5402,24 @@ static void test_GetAddrInfoW(void)
     pFreeAddrInfoW(result);
 
     result = NULL;
+    ret = pGetAddrInfoW(NULL, empty, NULL, &result);
+    ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
+    ok(result != NULL, "GetAddrInfoW failed\n");
+    pFreeAddrInfoW(result);
+
+    result = NULL;
     ret = pGetAddrInfoW(empty, zero, NULL, &result);
     ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
     ok(result != NULL, "GetAddrInfoW failed\n");
     pFreeAddrInfoW(result);
 
     result = NULL;
+    ret = pGetAddrInfoW(empty, empty, NULL, &result);
+    ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
+    ok(result != NULL, "GetAddrInfoW failed\n");
+    pFreeAddrInfoW(result);
+
+    result = NULL;
     ret = pGetAddrInfoW(localhost, NULL, NULL, &result);
     ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
     pFreeAddrInfoW(result);
@@ -5529,12 +5541,24 @@ static void test_getaddrinfo(void)
     pfreeaddrinfo(result);
 
     result = NULL;
+    ret = pgetaddrinfo(NULL, "", NULL, &result);
+    ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
+    ok(result != NULL, "getaddrinfo failed\n");
+    pfreeaddrinfo(result);
+
+    result = NULL;
     ret = pgetaddrinfo("", "0", NULL, &result);
     ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
     ok(result != NULL, "getaddrinfo failed\n");
     pfreeaddrinfo(result);
 
     result = NULL;
+    ret = pgetaddrinfo("", "", NULL, &result);
+    ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
+    ok(result != NULL, "getaddrinfo failed\n");
+    pfreeaddrinfo(result);
+
+    result = NULL;
     ret = pgetaddrinfo("localhost", NULL, NULL, &result);
     ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
     pfreeaddrinfo(result);


More information about the wine-patches mailing list