From 76e5d16734db378377800fff12d3bafc4fe31a09 Mon Sep 17 00:00:00 2001 From: past-due <30942300+past-due@users.noreply.github.com> Date: Fri, 22 Sep 2023 20:38:32 -0400 Subject: [PATCH] NETdecryptSecuredNetMessage: Additional validity checks --- lib/netplay/nettypes.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/netplay/nettypes.cpp b/lib/netplay/nettypes.cpp index 5e29f13b17f..b0042dc5e60 100644 --- a/lib/netplay/nettypes.cpp +++ b/lib/netplay/nettypes.cpp @@ -547,6 +547,12 @@ void NETclearSessionKeys(uint8_t player) netSessionKeys[player].reset(); } +bool NETisExpectedSecuredMessageType(uint8_t type) +{ + // currently there are no expected secured messages + return false; +} + // For encoding a secured net message, for a *specific player* // Returns `false` on failure // Notes: @@ -558,6 +564,7 @@ bool NETbeginEncodeSecured(NETQUEUE queue, uint8_t type) ASSERT_OR_RETURN(false, queue.index != realSelectedPlayer, "Secured messages are for other players, not ourselves."); ASSERT_OR_RETURN(false, queue.index < MAX_PLAYERS, "Invalid recipient (queue.index == %u)", static_cast(queue.index)); ASSERT_OR_RETURN(false, netSessionKeys[queue.index] != nullptr, "Lacking session key for player: %u", static_cast(queue.index)); + ASSERT(NETisExpectedSecuredMessageType(type), "Message type is not expected to be secured, and will be ignored on receipt"); NETbeginEncode(queue, type); bSecretMessageWrap = true; @@ -615,6 +622,13 @@ bool NETdecryptSecuredNetMessage(NETQUEUE queue, uint8_t& type) return false; } + if (!NETisExpectedSecuredMessageType(decryptedMessage.type)) + { + // Ignore message types that aren't expected to be secured + debug(LOG_NET, "Not a message type that's expected to be secured: (type: %s) - ignoring", messageTypeToString(decryptedMessage.type)); + return false; + } + NETlogPacket(NET_SECURED_NET_MESSAGE, static_cast(encryptedMessage.rawLen()), true); type = decryptedMessage.type; // must update type!