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

Fetching user/group info causes race conditions #994

Merged
merged 3 commits into from
Oct 23, 2024

Conversation

jmschonfeld
Copy link
Contributor

We call a variety of functions like getpwnam/getpwuid/getgrgid to fetch information about users and groups. These functions are not thread safe (causing crashes during execution of the functions) and also return inner pointers which can be overwritten out from under us. To resolve these race conditions, this switches to the _r variants of the functions which use a client-supplied buffer for populating the result. I consolidated these calls into functions on the Platform namespace and updated call sites throughout swift-foundation to avoid the functions that can race.

Resolves #982

@jmschonfeld
Copy link
Contributor Author

@swift-ci please test

}
}

static func uidFor(name: String) -> uid_t? {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have to block this PR on it, but I think the more canonically named version with be uid(forName name: String) (etc.)

@jmschonfeld
Copy link
Contributor Author

@swift-ci please test

@jmschonfeld
Copy link
Contributor Author

@swift-ci please test

@jmschonfeld jmschonfeld merged commit 71eefee into swiftlang:main Oct 23, 2024
3 checks passed
@jmschonfeld jmschonfeld deleted the user-group-races branch October 23, 2024 16:18
jmschonfeld added a commit to jmschonfeld/swift-foundation that referenced this pull request Oct 23, 2024
* Avoid racy stdlib functions for fetching user/group info

* Refactor naming

* Fix build failure
jmschonfeld added a commit that referenced this pull request Oct 23, 2024
* Avoid racy stdlib functions for fetching user/group info

* Refactor naming

* Fix build failure
cthielen pushed a commit to cthielen/swift-foundation that referenced this pull request Nov 8, 2024
* Avoid racy stdlib functions for fetching user/group info

* Refactor naming

* Fix build failure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash When Streaming Files with Vapor - Related to swift-foundation
2 participants