Bruno Jesus : ws2_32: Filter invalid socket parameters and return the appropriate error.

Alexandre Julliard julliard at winehq.org
Tue Sep 17 15:25:54 CDT 2013


Module: wine
Branch: master
Commit: 0298165bea97e577401383eb62bd0c882116fbd9
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=0298165bea97e577401383eb62bd0c882116fbd9

Author: Bruno Jesus <00cpxxx at gmail.com>
Date:   Tue Sep 17 10:00:52 2013 -0300

ws2_32: Filter invalid socket parameters and return the appropriate error.

---

 dlls/ws2_32/socket.c     |   48 +++++++++++++++++++++++++++++++++++++++++----
 dlls/ws2_32/tests/sock.c |   20 +++++++++++-------
 2 files changed, 55 insertions(+), 13 deletions(-)

diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index 1e2c44e..e8d87da 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -5868,6 +5868,7 @@ SOCKET WINAPI WSASocketW(int af, int type, int protocol,
 {
     SOCKET ret;
     DWORD err;
+    int unixaf, unixtype;
 
    /*
       FIXME: The "advanced" parameters of WSASocketW (lpProtocolInfo,
@@ -5913,14 +5914,50 @@ SOCKET WINAPI WSASocketW(int af, int type, int protocol,
         }
     }
 
-    /* convert the socket family and type */
-    af = convert_af_w2u(af);
-    type = convert_socktype_w2u(type);
+    /* convert the socket family, type and protocol */
+    unixaf = convert_af_w2u(af);
+    unixtype = convert_socktype_w2u(type);
+    protocol = convert_proto_w2u(protocol);
+    if (unixaf == AF_UNSPEC) unixaf = -1;
+
+    /* filter invalid parameters */
+    if (protocol < 0)
+    {
+        /* the type could not be converted */
+        if (type && unixtype < 0)
+        {
+            err = WSAESOCKTNOSUPPORT;
+            goto done;
+        }
+
+        err = WSAEPROTONOSUPPORT;
+        goto done;
+    }
+    if (unixaf < 0)
+    {
+        /* both family and protocol can't be invalid */
+        if (protocol <= 0)
+        {
+            err = WSAEINVAL;
+            goto done;
+        }
+
+        /* family could not be converted and neither socket type */
+        if (unixtype < 0 && af >= 0)
+        {
+
+            err = WSAESOCKTNOSUPPORT;
+            goto done;
+        }
+
+        err = WSAEAFNOSUPPORT;
+        goto done;
+    }
 
     SERVER_START_REQ( create_socket )
     {
-        req->family     = af;
-        req->type       = type;
+        req->family     = unixaf;
+        req->type       = unixtype;
         req->protocol   = protocol;
         req->access     = GENERIC_READ|GENERIC_WRITE|SYNCHRONIZE;
         req->attributes = OBJ_INHERIT;
@@ -5952,6 +5989,7 @@ SOCKET WINAPI WSASocketW(int af, int type, int protocol,
             err = WSAEPROTONOSUPPORT;
     }
 
+done:
     WARN("\t\tfailed, error %d!\n", err);
     SetLastError(err);
     return INVALID_SOCKET;
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index a9e6333..3921262 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -1784,7 +1784,6 @@ static void test_WSASocket(void)
     ok(WSASocketA(0, 0, 0, NULL, 0, 0) == INVALID_SOCKET,
        "WSASocketA should have failed\n");
     err = WSAGetLastError();
-todo_wine
     ok(err == WSAEINVAL, "Expected 10022, received %d\n", err);
 
     sock = WSASocketA(AF_INET, 0, 0, NULL, 0, 0);
@@ -1811,10 +1810,21 @@ todo_wine
     ok(WSASocketA(0, -1, 0, NULL, 0, 0) == INVALID_SOCKET,
        "WSASocketA should have failed\n");
     err = WSAGetLastError();
-todo_wine
     ok(err == WSAEINVAL, "Expected 10022, received %d\n", err);
 
     SetLastError(0xdeadbeef);
+    ok(WSASocketA(AF_INET, -1, 0, NULL, 0, 0) == INVALID_SOCKET,
+       "WSASocketA should have failed\n");
+    err = WSAGetLastError();
+    ok(err == WSAESOCKTNOSUPPORT, "Expected 10044, received %d\n", err);
+
+    SetLastError(0xdeadbeef);
+    ok(WSASocketA(AF_INET, 0, -1, NULL, 0, 0) == INVALID_SOCKET,
+       "WSASocketA should have failed\n");
+    err = WSAGetLastError();
+    ok(err == WSAEPROTONOSUPPORT, "Expected 10043, received %d\n", err);
+
+    SetLastError(0xdeadbeef);
     ok(WSASocketA(0, -1, -1, NULL, 0, 0) == INVALID_SOCKET,
        "WSASocketA should have failed\n");
     err = WSAGetLastError();
@@ -1824,7 +1834,6 @@ todo_wine
     ok(WSASocketA(-1, SOCK_STREAM, IPPROTO_UDP, NULL, 0, 0) == INVALID_SOCKET,
        "WSASocketA should have failed\n");
     err = WSAGetLastError();
-todo_wine
     ok(err == WSAEAFNOSUPPORT, "Expected 10047, received %d\n", err);
 
     sock = WSASocketA(AF_INET, 0, IPPROTO_TCP, NULL, 0, 0);
@@ -1835,14 +1844,12 @@ todo_wine
     ok(WSASocketA(0, SOCK_STREAM, 0, NULL, 0, 0) == INVALID_SOCKET,
        "WSASocketA should have failed\n");
     err = WSAGetLastError();
-todo_wine
     ok(err == WSAEINVAL, "Expected 10022, received %d\n", err);
 
     SetLastError(0xdeadbeef);
     ok(WSASocketA(0, 0, 0xdead, NULL, 0, 0) == INVALID_SOCKET,
        "WSASocketA should have failed\n");
     err = WSAGetLastError();
-todo_wine
     ok(err == WSAEPROTONOSUPPORT, "Expected 10043, received %d\n", err);
 
     SetLastError(0xdeadbeef);
@@ -1855,7 +1862,6 @@ todo_wine
     ok(WSASocketA(0, 0xdead, 0, NULL, 0, 0) == INVALID_SOCKET,
        "WSASocketA should have failed\n");
     err = WSAGetLastError();
-todo_wine
     ok(err == WSAEINVAL, "Expected 10022, received %d\n", err);
 
     sock = WSASocketA(0, 0, IPPROTO_TCP, NULL, 0, 0);
@@ -1917,7 +1923,6 @@ todo_wine
     ok(WSASocketA(0, 0, IPPROTO_UDP, &pi[0], 0, 0) == INVALID_SOCKET,
        "WSASocketA should have failed\n");
     err = WSAGetLastError();
-todo_wine
     ok(err == WSAEAFNOSUPPORT, "Expected 10047, received %d\n", err);
 
     pi[0].iProtocol = 0;
@@ -1932,7 +1937,6 @@ todo_wine
     else
     {
       err = WSAGetLastError();
-todo_wine
       ok(err == WSAEAFNOSUPPORT, "Expected 10047, received %d\n", err);
     }
 




More information about the wine-cvs mailing list