From b2572c7ca8f0df9bd1d8ee09f313fd318abe7e0c Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sat, 11 May 2024 10:05:31 +0100 Subject: [PATCH] Fix #12563: Race condition setting finish flag in WinHTTP --- src/network/core/http_winhttp.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/network/core/http_winhttp.cpp b/src/network/core/http_winhttp.cpp index ccba25ee62..11fa7bf5b7 100644 --- a/src/network/core/http_winhttp.cpp +++ b/src/network/core/http_winhttp.cpp @@ -121,8 +121,8 @@ void NetworkHTTPRequest::WinHttpCallback(DWORD code, void *info, DWORD length) /* Make sure we are not in a redirect loop. */ if (this->depth++ > 5) { Debug(net, 0, "HTTP request failed: too many redirects"); - this->finished = true; this->callback.OnFailure(); + this->finished = true; return; } break; @@ -144,8 +144,8 @@ void NetworkHTTPRequest::WinHttpCallback(DWORD code, void *info, DWORD length) if (status_code >= 400) { /* No need to be verbose about rate limiting. */ Debug(net, status_code == HTTP_429_TOO_MANY_REQUESTS ? 1 : 0, "HTTP request failed: status-code {}", status_code); - this->finished = true; this->callback.OnFailure(); + this->finished = true; return; } @@ -183,14 +183,14 @@ void NetworkHTTPRequest::WinHttpCallback(DWORD code, void *info, DWORD length) case WINHTTP_CALLBACK_STATUS_SECURE_FAILURE: case WINHTTP_CALLBACK_STATUS_REQUEST_ERROR: Debug(net, 0, "HTTP request failed: {}", GetLastErrorAsString()); - this->finished = true; this->callback.OnFailure(); + this->finished = true; break; default: Debug(net, 0, "HTTP request failed: unexepected callback code 0x{:x}", code); - this->finished = true; this->callback.OnFailure(); + this->finished = true; return; } } @@ -233,8 +233,8 @@ void NetworkHTTPRequest::Connect() this->connection = WinHttpConnect(_winhttp_session, url_components.lpszHostName, url_components.nPort, 0); if (this->connection == nullptr) { Debug(net, 0, "HTTP request failed: {}", GetLastErrorAsString()); - this->finished = true; this->callback.OnFailure(); + this->finished = true; return; } @@ -243,8 +243,8 @@ void NetworkHTTPRequest::Connect() WinHttpCloseHandle(this->connection); Debug(net, 0, "HTTP request failed: {}", GetLastErrorAsString()); - this->finished = true; this->callback.OnFailure(); + this->finished = true; return; } @@ -267,8 +267,8 @@ bool NetworkHTTPRequest::Receive() { if (this->callback.cancelled && !this->finished) { Debug(net, 1, "HTTP request failed: cancelled by user"); - this->finished = true; this->callback.OnFailure(); + this->finished = true; /* Fall-through, as we are waiting for IsQueueEmpty() to happen. */ }