diff options
| author | agalq13 <71724834+agalq13@users.noreply.github.com> | 2026-06-11 12:35:30 +0300 |
|---|---|---|
| committer | agalq13 <71724834+agalq13@users.noreply.github.com> | 2026-06-11 13:20:48 +0300 |
| commit | 29e577d966ae48810507c7a016ff1489a5843b2c (patch) | |
| tree | d55e4b4ecef6104436a2e37a3d15e6d8db0d46a6 | |
| parent | 1bc93fd16d5a452bedcc5437923abd0d9fcb8c52 (diff) | |
NetPlay: Validate controller packet indices
| -rw-r--r-- | Source/Core/Core/NetPlayServer.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index d26cc399c1..f37bc4200c 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -192,6 +192,12 @@ static void ClearPeerPlayerId(ENetPeer* peer) } } +template <typename T> +static bool IsValidPadIndex(const T& map_array, PadIndex index) +{ + return index >= 0 && static_cast<size_t>(index) < map_array.size(); +} + void NetPlayServer::SetupIndex() { if (!Config::Get(Config::NETPLAY_USE_INDEX) || Config::Get(Config::NETPLAY_INDEX_NAME).empty() || @@ -814,7 +820,7 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player) // If the data is not from the correct player, // then disconnect them. - if (m_pad_map.at(map) != player.pid) + if (!IsValidPadIndex(m_pad_map, map) || m_pad_map.at(map) != player.pid) { return 1; } @@ -862,6 +868,9 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player) PadIndex map; packet >> map; + if (!IsValidPadIndex(m_pad_map, map)) + return 1; + GCPadStatus pad; packet >> pad.button; spac << map << pad.button; @@ -895,7 +904,7 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player) // If the data is not from the correct player, // then disconnect them. - if (m_wiimote_map.at(map) != player.pid) + if (!IsValidPadIndex(m_wiimote_map, map) || m_wiimote_map.at(map) != player.pid) { return 1; } |
