From 15978ddc01c56c085499066b3b871bbdfaac595a Mon Sep 17 00:00:00 2001 From: Jeff Zaroyko Date: Wed, 10 Sep 2008 05:34:41 +1000 Subject: [PATCH] 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(+) diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 69d678c8fa8..f95f8bd401a 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 4b8c57f652b..680c75a980a 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(); -- 2.11.4.GIT