Kai Blin : ws2_32: Cope with buggy apps passing setsockopt optval as a value instead of a pointer .

Alexandre Julliard julliard at winehq.org
Mon Nov 12 06:27:53 CST 2007


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

Author: Kai Blin <kai.blin at gmail.com>
Date:   Mon Nov 12 11:42:28 2007 +0100

ws2_32: Cope with buggy apps passing setsockopt optval as a value instead of a pointer.

---

 dlls/ws2_32/socket.c     |    7 +++++++
 dlls/ws2_32/tests/sock.c |   11 ++++++++++-
 2 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index 4c185d8..f4111cd 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -2812,6 +2812,13 @@ int WINAPI WS_setsockopt(SOCKET s, int level, int optname,
     TRACE("socket: %04lx, level 0x%x, name 0x%x, ptr %p, len %d\n",
           s, level, optname, optval, optlen);
 
+    /* some broken apps pass the value directly instead of a pointer to it */
+    if(IS_INTRESOURCE(optval))
+    {
+        SetLastError(WSAEFAULT);
+        return SOCKET_ERROR;
+    }
+
     switch(level)
     {
     case WS_SOL_SOCKET:
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index 8225f5f..858d0b5 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -850,7 +850,7 @@ LINGER linger_testvals[] = {
 static void test_set_getsockopt(void)
 {
     SOCKET s;
-    int i, err;
+    int i, err, lasterr;
     int timeout;
     LINGER lingval;
     int size;
@@ -889,6 +889,15 @@ static void test_set_getsockopt(void)
                  lingval.l_onoff, lingval.l_linger,
                  linger_testvals[i].l_onoff, linger_testvals[i].l_linger);
     }
+    /* Test for erroneously passing a value instead of a pointer as optval */
+    size = sizeof(char);
+    err = setsockopt(s, SOL_SOCKET, SO_DONTROUTE, (char *)1, size);
+    ok(err == SOCKET_ERROR, "setsockopt with optval being a value passed "
+                            "instead of failing.\n");
+    lasterr = WSAGetLastError();
+    ok(lasterr == WSAEFAULT, "setsockopt with optval being a value "
+                             "returned 0x%08x, not WSAEFAULT(0x%08x)\n",
+                             lasterr, WSAEFAULT);
     closesocket(s);
 }
 




More information about the wine-cvs mailing list