Skip to content

fix: Don't accept invalid connections in UnityTransport.Send #3382

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
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
1 change: 1 addition & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Fixed

- Fixed an issue in `UnityTransport` where the transport would accept sends on invalid connections, leading to a useless memory allocation and confusing error message. (#3382)
- Fixed issue where the time delta that interpolators used would not be properly updated during multiple fixed update invocations within the same player loop frame. (#3355)
- Fixed issue when using a distributed authority network topology and many clients attempt to connect simultaneously the session owner could max-out the maximum in-flight reliable messages allowed, start dropping packets, and some of the connecting clients would fail to fully synchronize. (#3350)
- Fixed issue when using a distributed authority network topology and scene management was disabled clients would not be able to spawn any new network prefab instances until synchronization was complete. (#3350)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1347,8 +1347,13 @@ public override NetcodeNetworkEvent PollEvent(out ulong clientId, out ArraySegme
/// <param name="networkDelivery">The delivery type (QoS) to send data with</param>
public override void Send(ulong clientId, ArraySegment<byte> payload, NetworkDelivery networkDelivery)
{
var pipeline = SelectSendPipeline(networkDelivery);
var connection = ParseClientId(clientId);
if (!m_Driver.IsCreated || m_Driver.GetConnectionState(connection) != NetworkConnection.State.Connected)
{
return;
}

var pipeline = SelectSendPipeline(networkDelivery);
if (pipeline != m_ReliableSequencedPipeline && payload.Count > m_MaxPayloadSize)
{
Debug.LogError($"Unreliable payload of size {payload.Count} larger than configured 'Max Payload Size' ({m_MaxPayloadSize}).");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,5 +483,22 @@ public IEnumerator DoesNotActAfterShutdown([Values] AfterShutdownAction afterShu
yield return EnsureNoNetworkEvent(m_Client1Events);
}
}

[UnityTest]
public IEnumerator DoesNotAttemptToSendOnInvalidConnections()
{
InitializeTransport(out m_Server, out m_ServerEvents);
InitializeTransport(out m_Client1, out m_Client1Events);

m_Server.StartServer();
m_Client1.StartClient();

yield return WaitForNetworkEvent(NetworkEvent.Connect, m_Client1Events);

var data = new ArraySegment<byte>(new byte[42]);
m_Server.Send(0, data, NetworkDelivery.Reliable);

yield return EnsureNoNetworkEvent(m_Client1Events);
}
}
}