gh-127081: fix some un-thread-safe use of libc functions#132591
Closed
duaneg wants to merge 8 commits intopython:mainfrom
Closed
gh-127081: fix some un-thread-safe use of libc functions#132591duaneg wants to merge 8 commits intopython:mainfrom
duaneg wants to merge 8 commits intopython:mainfrom
Conversation
Add configure tests and defines for getservbyname_r, getservbyport_r, and getprotobyname_r. Use these if available, otherwise fallback to the thread-unsafe variants. Add a unit test to exercise getprotobyname, which is currently untested. TODO: - Are there any platforms which define the unsafe variants but not the re-entrant ones? If not we can simplify the #ifdef hell somewhat. - Do the re-entrant functions have the same signature on all platforms? - These changes follow the existing code's practice: allocate a fixed-size (and overly large) buffer, and don't properly handle the error case if it is too small. Should this be fixed? If so should existing code also be fixed?
The libc setpwent, getpwent, and endpwent functions are not thread-safe. Protect them with mutexs in free-threading builds.
The dbm_* functions are not thread-safe, naturally. Add critical sections to protect their use.
The getlogin function is not thread-safe: replace with getlogin_r where available. Note that this function is untested (unit test is skipped with a note it caused CI failures as behaviour differs between NIX environments).
Member
|
Can you split the PR into multiple ones where each PR is dedicated to a single module please (dbm and gdbm can be put together)? it's easier to revert commits if needs arise and we can also merge them separately. |
Contributor
Author
Definitely! Good suggestion, thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add configure tests and defines for getservbyname_r, getservbyport_r, and getprotobyname_r. Use these if available, otherwise fallback to the thread-unsafe variants.
Add a unit test to exercise getprotobyname, which is currently untested.
TODO: