[PATCH] ws2_32: Cope with NULL address in connect() call

Bruno Jesus 00cpxxx at gmail.com
Sun Feb 26 19:25:43 CST 2017


From: Bruno Jesus <bjesus at codeweavers.com>

Fixes a problem in Race 07 game.

Signed-off-by: Bruno Jesus <bjesus at codeweavers.com>
---
 dlls/ws2_32/socket.c     | 7 +++++--
 dlls/ws2_32/tests/sock.c | 5 +++++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index 3c8c806..f0e8f2a 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -1731,14 +1731,17 @@ static inline BOOL supported_protocol(int protocol)
 
 /**********************************************************************/
 
-/* Returns the length of the converted address if successful, 0 if it was too small to
- * start with.
+/* Returns the length of the converted address if successful, 0 if it was too
+ * small to start with or unknown family or invalid address buffer.
  */
 static unsigned int ws_sockaddr_ws2u(const struct WS_sockaddr* wsaddr, int wsaddrlen,
                                      union generic_unix_sockaddr *uaddr)
 {
     unsigned int uaddrlen = 0;
 
+    if (!wsaddr)
+        return 0;
+
     switch (wsaddr->sa_family)
     {
 #ifdef HAS_IPX
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index 59a23d7..b42c078 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -5841,6 +5841,11 @@ static void test_events(int useMessages)
         goto end;
     }
 
+    SetLastError(0xdeadbeef);
+    ret = connect(src, NULL, 0);
+    ok(ret == SOCKET_ERROR, "expected -1, got %d\n", ret);
+    ok(GetLastError() == WSAEFAULT, "expected 10014, got %d\n", GetLastError());
+
     ret = connect(src, (struct sockaddr*)&addr, sizeof(addr));
     if (ret == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK)
     {
-- 
2.9.3




More information about the wine-patches mailing list