Jeff Zaroyko : ws2_32: ioctlsocket should try to check if argp is valid.

Alexandre Julliard julliard at winehq.org
Wed Sep 10 06:01:43 CDT 2008


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

Author: Jeff Zaroyko <jeffz at jeffz.name>
Date:   Wed Sep 10 05:34:41 2008 +1000

ws2_32: ioctlsocket should try to check if argp is valid.

---

 dlls/ws2_32/socket.c     |    6 ++++++
 dlls/ws2_32/tests/sock.c |   27 +++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index 69d678c..f95f8bd 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -2345,6 +2345,12 @@ int WINAPI WS_ioctlsocket(SOCKET s, LONG cmd, WS_u_long *argp)
     long newcmd  = cmd;
 
     TRACE("socket %04lx, cmd %08x, ptr %p\n", s, cmd, argp);
+    /* broken apps like defcon pass the argp value directly instead of a pointer to it */
+    if(IS_INTRESOURCE(argp))
+    {
+       SetLastError(WSAEFAULT);
+       return SOCKET_ERROR;
+    }
 
     switch( cmd )
     {
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index 4b8c57f..680c75a 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -3,6 +3,7 @@
  *
  * Copyright 2002 Martin Wilck
  * Copyright 2005 Thomas Kho
+ * Copyright 2008 Jeff Zaroyko
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -1989,6 +1990,31 @@ static void test_inet_addr(void)
     ok(addr == INADDR_NONE, "inet_addr succeeded unexpectedly\n");
 }
 
+static void test_ioctlsocket(void)
+{
+    SOCKET sock;
+    int ret;
+    long cmds[] = {FIONBIO, FIONREAD, SIOCATMARK};
+    int i;
+
+    sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+    ok(sock != INVALID_SOCKET, "Creating the socket failed: %d\n", WSAGetLastError());
+    if(sock == INVALID_SOCKET)
+    {
+        skip("Can't continue without a socket.\n");
+        return;
+    }
+
+    for(i = 0; i < sizeof(cmds)/sizeof(long); i++)
+    {
+        /* broken apps like defcon pass the argp value directly instead of a pointer to it */
+        ret = ioctlsocket(sock, cmds[i], (u_long *)1);
+        ok(ret == SOCKET_ERROR, "ioctlsocket succeeded unexpectedly\n");
+        ret = WSAGetLastError();
+        ok(ret == WSAEFAULT, "expected WSAEFAULT, got %d instead\n", ret);
+    }
+}
+
 static DWORD WINAPI drain_socket_thread(LPVOID arg)
 {
     char buffer[1024];
@@ -2304,6 +2330,7 @@ START_TEST( sock )
     test_accept();
     test_getsockname();
     test_inet_addr();
+    test_ioctlsocket();
     test_dns();
     test_gethostbyname_hack();
 




More information about the wine-cvs mailing list