Skip to content

Commit

Permalink
[9.0] Guard against empty Accept address (#111366)
Browse files Browse the repository at this point in the history
* guard agains empty Accept address

* remove assert

* add comment

---------

Co-authored-by: wfurt <[email protected]>
  • Loading branch information
github-actions[bot] and wfurt authored Jan 14, 2025
1 parent fcee4ed commit 2b19745
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
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

0 comments on commit 2b19745

Please sign in to comment.