This repository was archived by the owner on Jan 23, 2023. It is now read-only.
release/2.0: Fix lifetime handling of ReceiveMessageFromAsync buffer on Windows#22013
Merged
stephentoub merged 3 commits intodotnet:release/2.0.0from Jul 10, 2017
Merged
release/2.0: Fix lifetime handling of ReceiveMessageFromAsync buffer on Windows#22013stephentoub merged 3 commits intodotnet:release/2.0.0from
stephentoub merged 3 commits intodotnet:release/2.0.0from
Conversation
The test currently only tests a single send/receive pair, which doesn't catch issues when trying to reuse a SocketAsyncEventArgs for multiple operations iteratively. The test is also duplicated for IPv4 and IPv6. Fix both issues.
When a ReceiveMessageFromAsync is first used with a SocketAsyncEventArgs instance, it initializes the _wsaMessageBuffer. Then in order to use the buffer, it pins it, storing both a GCHandle and a pointer to the target object. But if the SAEA's buffer is ever changed with, for example, a SetBuffer call, a routine is invoked on the SocketAsyncEventArgs that frees all of its pinned data, including these for the _wsaMessageBuffer. Then the next time ReceiveMessageFromAsync is used, this handle ends up not getting recreated, and we end up dereferencing a null pointer. The fix is to separate the creation of the buffer from the creation of the pinning handle, lazily initializing each independently. If the pinning handle is freed due to SetBuffer, the next invocation will reinitialize it.
|
LGTM |
Member
Author
|
@dotnet-bot test outerloop netcoreapp OSX10.12 Debug |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Port #22012 to release/2.0 branch
Fixes https://github.com/dotnet/corefx/issues/21995