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

[9.0] Guard against empty Accept address #111366

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3602,15 +3602,15 @@ internal void InternalSetBlocking(bool desired)
}

// CreateAcceptSocket - pulls unmanaged results and assembles them into a new Socket object.
internal Socket CreateAcceptSocket(SafeSocketHandle fd, EndPoint remoteEP)
internal Socket CreateAcceptSocket(SafeSocketHandle fd, EndPoint? remoteEP)
{
// Internal state of the socket is inherited from listener.
Debug.Assert(fd != null && !fd.IsInvalid);
Socket socket = new Socket(fd, loadPropertiesFromHandle: false);
return UpdateAcceptSocket(socket, remoteEP);
}

internal Socket UpdateAcceptSocket(Socket socket, EndPoint remoteEP)
internal Socket UpdateAcceptSocket(Socket socket, EndPoint? remoteEP)
{
// Internal state of the socket is inherited from listener.
socket._addressFamily = _addressFamily;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ private void CompleteAcceptOperation(IntPtr acceptedFileDescriptor, Memory<byte>
_acceptedFileDescriptor = acceptedFileDescriptor;
if (socketError == SocketError.Success)
{
Debug.Assert(socketAddress.Length > 0);
_acceptAddressBufferCount = socketAddress.Length;
}
else
Expand Down Expand Up @@ -348,9 +347,10 @@ private SocketError FinishOperationAccept(SocketAddress remoteSocketAddress)
new ReadOnlySpan<byte>(_acceptBuffer, 0, _acceptAddressBufferCount).CopyTo(remoteSocketAddress.Buffer.Span);
remoteSocketAddress.Size = _acceptAddressBufferCount;

// on macOS accept can sometimes return empty remote address even when it returns successfully.
Socket acceptedSocket = _currentSocket!.CreateAcceptSocket(
SocketPal.CreateSocket(_acceptedFileDescriptor),
_currentSocket._rightEndPoint!.Create(remoteSocketAddress));
remoteSocketAddress.Size > 0 ? _currentSocket._rightEndPoint!.Create(remoteSocketAddress) : null);
if (_acceptSocket is null)
{
// Store the accepted socket
Expand Down
Loading