[PATCH 1/2] ws2_32: Set WSAEINVAL in InetPtonW if the address string is unparsable

Alex Henrie alexhenrie24 at gmail.com
Mon May 18 22:22:12 CDT 2020


Signed-off-by: Alex Henrie <alexhenrie24 at gmail.com>
---
 dlls/ws2_32/socket.c     |  1 +
 dlls/ws2_32/tests/sock.c | 15 +++++++++------
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index a5df51d421..d57fc9ecd2 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -8450,6 +8450,7 @@ INT WINAPI InetPtonW(INT family, PCWSTR addr, PVOID buffer)
     WideCharToMultiByte(CP_ACP, 0, addr, -1, addrA, len, NULL, NULL);
 
     ret = WS_inet_pton(family, addrA, buffer);
+    if (!ret) SetLastError(WSAEINVAL);
 
     HeapFree(GetProcessHeap(), 0, addrA);
     return ret;
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index 9c996037ce..dcbc9377d7 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -5014,11 +5014,11 @@ static void test_inet_pton(void)
         WSASetLastError(0xdeadbeef);
         ret = pInetPtonA(tests[i].family, tests[i].printable, buffer);
         ok (ret == tests[i].ret, "Test [%d]: Expected %d, got %d\n", i, tests[i].ret, ret);
+        err = WSAGetLastError();
         if (tests[i].ret == -1)
-        {
-            err = WSAGetLastError();
             ok (tests[i].err == err, "Test [%d]: Expected 0x%x, got 0x%x\n", i, tests[i].err, err);
-        }
+        else
+            ok (err == 0xdeadbeef, "Test [%d]: Expected 0xdeadbeef, got 0x%x\n", i, tests[i].err, err);
         if (tests[i].ret != 1) continue;
         ok (memcmp(buffer, tests[i].raw_data,
             tests[i].family == AF_INET ? sizeof(struct in_addr) : sizeof(struct in6_addr)) == 0,
@@ -5041,11 +5041,14 @@ static void test_inet_pton(void)
         WSASetLastError(0xdeadbeef);
         ret = pInetPtonW(tests[i].family, tests[i].printable ? printableW : NULL, buffer);
         ok(ret == tests[i].ret, "Test [%d]: Expected %d, got %d\n", i, tests[i].ret, ret);
+        err = WSAGetLastError();
         if (tests[i].ret == -1)
-        {
-            err = WSAGetLastError();
             ok(tests[i].err == err, "Test [%d]: Expected 0x%x, got 0x%x\n", i, tests[i].err, err);
-        }
+        else if (tests[i].ret == 0)
+            ok(err == WSAEINVAL || broken(err == 0xdeadbeef) /* win2008 */,
+               "Test [%d]: Expected WSAEINVAL, got 0x%x\n", i, err);
+        else
+            ok(err == 0xdeadbeef, "Test [%d]: Expected 0xdeadbeef, got 0x%x\n", i, err);
         if (tests[i].ret != 1) continue;
         ok(memcmp(buffer, tests[i].raw_data,
            tests[i].family == AF_INET ? sizeof(struct in_addr) : sizeof(struct in6_addr)) == 0,
-- 
2.26.2




More information about the wine-devel mailing list