From b9f8adb243a21af1df84cd691d47a665ab87c458 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Mon, 19 Oct 2020 11:21:20 -0500 Subject: [PATCH] server: Forbid accepting into the same socket more than once. Signed-off-by: Zebediah Figura Signed-off-by: Alexandre Julliard --- dlls/ws2_32/tests/sock.c | 16 +--------------- server/sock.c | 7 +++++++ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index 7c36456c91f..9357ad0d872 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -7554,23 +7554,9 @@ todo_wine bret = pAcceptEx(listener, acceptor, buffer, 0, sizeof(struct sockaddr_in) + 16, sizeof(struct sockaddr_in) + 16, &bytesReturned, &overlapped); - todo_wine ok(bret == FALSE && WSAGetLastError() == WSAEINVAL, + ok(bret == FALSE && WSAGetLastError() == WSAEINVAL, "AcceptEx on already pending socket returned %d + errno %d\n", bret, WSAGetLastError()); ok(overlapped.Internal == STATUS_PENDING, "got %08x\n", (ULONG)overlapped.Internal); - if (bret == FALSE && WSAGetLastError() == ERROR_IO_PENDING) { - /* We need to cancel this call, otherwise things fail */ - bret = CancelIo((HANDLE) listener); - ok(bret, "Failed to cancel failed test. Bailing...\n"); - if (!bret) return; - WaitForSingleObject(overlapped.hEvent, 0); - - overlapped.Internal = 0xdeadbeef; - bret = pAcceptEx(listener, acceptor, buffer, 0, - sizeof(struct sockaddr_in) + 16, sizeof(struct sockaddr_in) + 16, - &bytesReturned, &overlapped); - ok(bret == FALSE && WSAGetLastError() == ERROR_IO_PENDING, "AcceptEx returned %d + errno %d\n", bret, WSAGetLastError()); - ok(overlapped.Internal == STATUS_PENDING, "got %08x\n", (ULONG)overlapped.Internal); - } iret = connect(acceptor, (struct sockaddr*)&bindAddress, sizeof(bindAddress)); todo_wine ok(iret == SOCKET_ERROR && WSAGetLastError() == WSAEINVAL, diff --git a/server/sock.c b/server/sock.c index 24693a42fa3..866a9351152 100644 --- a/server/sock.c +++ b/server/sock.c @@ -1463,6 +1463,13 @@ static int sock_ioctl( struct fd *fd, ioctl_code_t code, struct async *async ) if (!(acceptsock = (struct sock *)get_handle_obj( current->process, params->accept_handle, access, &sock_ops ))) return 0; + if (acceptsock->accept_recv_req) + { + release_object( acceptsock ); + set_win32_error( WSAEINVAL ); + return 0; + } + if (!(req = alloc_accept_req( acceptsock, async, params ))) return 0; list_add_tail( &sock->accept_list, &req->entry ); acceptsock->accept_recv_req = req;