From 6733c40d789744ec0ee6fa30f8e14816968a0887 Mon Sep 17 00:00:00 2001 From: Dan Kegel Date: Mon, 18 Oct 2010 10:42:16 +0000 Subject: [PATCH] ws2_32: Null select() should fail with WSAEINVAL. --- dlls/ws2_32/socket.c | 8 ++++++-- dlls/ws2_32/tests/sock.c | 11 +++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 22e6138d6df..66726a78288 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -3496,7 +3496,11 @@ static struct pollfd *fd_sets_to_poll( const WS_fd_set *readfds, const WS_fd_set if (writefds) count += writefds->fd_count; if (exceptfds) count += exceptfds->fd_count; *count_ptr = count; - if (!count) return NULL; + if (!count) + { + SetLastError(WSAEINVAL); + return NULL; + } if (!(fds = HeapAlloc( GetProcessHeap(), 0, count * sizeof(fds[0])))) { SetLastError( ERROR_NOT_ENOUGH_MEMORY ); @@ -3619,7 +3623,7 @@ int WINAPI WS_select(int nfds, WS_fd_set *ws_readfds, TRACE("read %p, write %p, excp %p timeout %p\n", ws_readfds, ws_writefds, ws_exceptfds, ws_timeout); - if (!(pollfds = fd_sets_to_poll( ws_readfds, ws_writefds, ws_exceptfds, &count )) && count) + if (!(pollfds = fd_sets_to_poll( ws_readfds, ws_writefds, ws_exceptfds, &count ))) return SOCKET_ERROR; if (ws_timeout) diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index e0f9ccfa92d..fd61e78a203 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -1943,6 +1943,17 @@ static void test_select(void) FD_ZERO(&readfds); FD_ZERO(&writefds); FD_ZERO(&exceptfds); + + SetLastError(0); + ret = select(maxfd+1, 0, 0, 0, &select_timeout); + ok ( (ret == SOCKET_ERROR), "expected SOCKET_ERROR, got %i\n", ret); + ok ( GetLastError() == WSAEINVAL, "expected WSAEINVAL, got %i\n", ret); + + SetLastError(0); + ret = select(maxfd+1, &readfds, &writefds, &exceptfds, &select_timeout); + ok ( (ret == SOCKET_ERROR), "expected SOCKET_ERROR, got %i\n", ret); + ok ( GetLastError() == WSAEINVAL, "expected WSAEINVAL, got %i\n", ret); + FD_SET(INVALID_SOCKET, &readfds); SetLastError(0); ret = select(maxfd+1, &readfds, &writefds, &exceptfds, &select_timeout);