From: Paul Gofman Subject: [PATCH 7/7] winhttp: Don't allow queueing websocket receive if another is pending. Message-Id: <20220127230631.744586-7-pgofman@codeweavers.com> Date: Fri, 28 Jan 2022 02:06:31 +0300 In-Reply-To: <20220127230631.744586-1-pgofman@codeweavers.com> References: <20220127230631.744586-1-pgofman@codeweavers.com> Signed-off-by: Paul Gofman --- dlls/winhttp/request.c | 15 +++++++++++++-- dlls/winhttp/tests/notification.c | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/dlls/winhttp/request.c b/dlls/winhttp/request.c index a61355da7b9..728b1895ba7 100644 --- a/dlls/winhttp/request.c +++ b/dlls/winhttp/request.c @@ -3743,13 +3743,24 @@ DWORD WINAPI WinHttpWebSocketReceive( HINTERNET hsocket, void *buf, DWORD len, D { struct socket_receive *r; - if (!(r = malloc( sizeof(*r) ))) return FALSE; + if (InterlockedIncrement( &socket->hdr.pending_receives ) > 1) + { + InterlockedDecrement( &socket->hdr.pending_receives ); + WARN( "Attempt to queue receive while another is pending.\n" ); + release_object( &socket->hdr ); + return ERROR_INVALID_OPERATION; + } + + if (!(r = malloc( sizeof(*r) ))) + { + InterlockedDecrement( &socket->hdr.pending_receives ); + return ERROR_OUTOFMEMORY; + } r->socket = socket; r->buf = buf; r->len = len; addref_object( &socket->hdr ); - InterlockedIncrement( &socket->hdr.pending_receives ); if ((ret = queue_task( &socket->recv_q, task_socket_receive, r ))) { InterlockedDecrement( &socket->hdr.pending_receives ); diff --git a/dlls/winhttp/tests/notification.c b/dlls/winhttp/tests/notification.c index fabc5a03a46..121190ba9d2 100644 --- a/dlls/winhttp/tests/notification.c +++ b/dlls/winhttp/tests/notification.c @@ -1104,6 +1104,8 @@ static void test_websocket(BOOL secure) err = pWinHttpWebSocketReceive( socket, buffer, sizeof(buffer), &size, &type ); ok( err == ERROR_SUCCESS, "got %u\n", err ); + err = pWinHttpWebSocketReceive( socket, buffer, sizeof(buffer), &size, &type ); + ok( err == ERROR_INVALID_OPERATION, "got %u\n", err ); setup_test( &info, winhttp_websocket_shutdown, __LINE__ ); ws_status = (WINHTTP_WEB_SOCKET_STATUS *)info.buffer; -- 2.34.1