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
Win32 OTTD2FS/FS2OTTD used from multiple threads but use a static buffer #8713
Comments
|
nielsmh
added a commit
to nielsmh/OpenTTD
that referenced
this issue
Feb 21, 2021
… instead of static buffers
nielsmh
added a commit
to nielsmh/OpenTTD
that referenced
this issue
Feb 21, 2021
… instead of static buffers
nielsmh
added a commit
to nielsmh/OpenTTD
that referenced
this issue
Feb 21, 2021
… instead of static buffers
nielsmh
added a commit
to nielsmh/OpenTTD
that referenced
this issue
Feb 21, 2021
… instead of static buffers
nielsmh
added a commit
to nielsmh/OpenTTD
that referenced
this issue
Feb 21, 2021
… instead of static buffers
nielsmh
added a commit
to nielsmh/OpenTTD
that referenced
this issue
Feb 23, 2021
… instead of static buffers
nielsmh
added a commit
to nielsmh/OpenTTD
that referenced
this issue
Apr 2, 2021
… instead of static buffers
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Version of OpenTTD
master
Expected result
No thread safety issues
Actual result
The OTTD2FS/FS2OTTD functions are used in a wide variety of places in the codebase, including indirectly from non-main threads. (e.g. file scanner thread, network threads when debug output is on, crash logger). Various macros also use these functions (e.g. fopen, MB_TO_WIDE/WIDE_TO_MB, etc.).
On Win32, these methods use a static buffer, and return a pointer to that buffer.
In the event that the method is called from multiple threads in the same general time frame, callers could receive output from a different thread. Theoretically this could result in a buffer over-read if a thread is reading the buffer at the same time as another is in the middle of writing it.
I used TLS to make this go away: JGRennison/OpenTTD-patches@0a61671. std::string conversion could also be an option.
Steps to reproduce
I'm sure there must be a way of automatically detecting this on Windows.
The text was updated successfully, but these errors were encountered: