Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Possible race condition in WinHTTP backend #12563

Closed
JGRennison opened this issue Apr 24, 2024 · 0 comments · Fixed by #12658
Closed

[Bug]: Possible race condition in WinHTTP backend #12563

JGRennison opened this issue Apr 24, 2024 · 0 comments · Fixed by #12658
Labels
bug Something isn't working

Comments

@JGRennison
Copy link
Contributor

Version of OpenTTD

master

Expected result

No possible race conditions, etc.

Actual result

In the WinHTTP backend there are various instances of this pattern:

		this->finished = true;
		this->callback.OnFailure();

where this is a NetworkHTTPRequest.

This appears to be a racy (albeit with a narrow window), because finished is made true before is the callback queue is appended to. If the callback queue was previously empty, it would appear that the NetworkHTTPRequest instance is liable for deletion via NetworkHTTPSocketHandler::HTTPReceive and NetworkHTTPRequest::Receive in the gap after finished is set to true, but before callback.OnFailure is called. It would seem that this could result in the call to callback.OnFailure being a use after free because *this has already been destructed.

Probably finished should be assigned after calling callback.OnFailure (i.e. release semantics), and in NetworkHTTPRequest::Receive it should be read once, first (i.e. acquire semantics).

Steps to reproduce

See http_winhttp.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants