diff options
| author | JosJuice <josjuice@gmail.com> | 2026-06-14 13:51:46 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-06-14 13:51:46 +0200 |
| commit | 107169bfd8a6d4f12dc1103d742cf6dd5f2348dd (patch) | |
| tree | d17599587e5ff0f924ccc06e147599d5bb66f0bc | |
| parent | f96a7682d45d1815cf419ed7461faace998389d1 (diff) | |
| parent | 5585aa0474771040bdf1703cf33068e3991937a2 (diff) | |
Merge pull request #14677 from doldol22312/netplay-validate-controller-packet-indices
NetPlayServer: Fix remote crash via invalid pad index
| -rw-r--r-- | Source/Core/Core/NetPlayServer.cpp | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index d26cc399c1..57cd691060 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() || @@ -533,6 +539,21 @@ unsigned int NetPlayServer::OnDisconnect(const Client& player) break; } } + + for (PlayerId& mapping : m_wiimote_map) + { + if (m_is_running && mapping == pid && pid != 1) + { + std::lock_guard lkg(m_crit.game); + m_is_running = false; + + sf::Packet spac; + spac << MessageID::DisableGame; + // this thread doesn't need players lock + SendToClients(spac); + break; + } + } } if (m_start_pending) @@ -814,7 +835,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 +883,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 +919,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; } |
