Skip to content

shims: fix a subtle bug in semaphore initialisation on Windows #791

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

Merged
merged 1 commit into from
May 24, 2023

Conversation

compnerd
Copy link
Member

This function is the initializer for the semaphore. The seamphore storage itself may be stack allocated (or heap allocated) but without guarantee of 0-initialisation. As a result, the subsequent CAS for the atomic replacement will fail silently, leaving the previously non-zero value in place, indicating that the value is a valid handle. This would fail randomly and would ultimately result in a crash in the CloseHandle call associated with the clean up.

This issue was identified by SwiftLint on Windows.

This function is the initializer for the semaphore.  The seamphore
storage itself may be stack allocated (or heap allocated) but without
guarantee of 0-initialisation.  As a result, the subsequent CAS for the
atomic replacement will fail silently, leaving the previously non-zero
value in place, indicating that the value is a valid handle.  This would
fail randomly and would ultimately result in a crash in the
`CloseHandle` call associated with the clean up.

This issue was identified by SwiftLint on Windows.
@compnerd
Copy link
Member Author

@swift-ci please test

@compnerd compnerd merged commit 2725ced into swiftlang:main May 24, 2023
@compnerd compnerd deleted the atomic-memset branch May 24, 2023 14:14
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.

1 participant