[PATCH 7/7] winhttp: Don't allow queueing websocket receive if another is pending.
Paul Gofman
pgofman at codeweavers.com
Thu Jan 27 17:06:31 CST 2022
Signed-off-by: Paul Gofman <pgofman at codeweavers.com>
---
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
More information about the wine-devel
mailing list