Skip to content

Commit 809242d

Browse files
authored
Merge pull request #496 from GeneralsOnlineDevelopmentTeam/seer/bugfix/network-router-bounds-check
bugfix(network): Prevent out-of-bounds access and improve fallback for packet router slots
2 parents 15cf476 + ee39d48 commit 809242d

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

Core/GameEngine/Source/GameNetwork/ConnectionManager.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ void ConnectionManager::updateRunAhead(Int oldRunAhead, Int frameRate, Bool didS
13441344
}
13451345
}
13461346

1347-
// 3) Convert jitter to a 0–1+ ratio relative to latency
1347+
// 3) Convert jitter to a 0–1+ ratio relative to latency
13481348
Real jitterRatio = 0.0f;
13491349
if (maxLatMs > 0)
13501350
{
@@ -1365,7 +1365,7 @@ void ConnectionManager::updateRunAhead(Int oldRunAhead, Int frameRate, Bool didS
13651365
}
13661366
else if (maxLatMs > 200)
13671367
{
1368-
// Medium-high latency (200–300 ms)
1368+
// Medium-high latency (200–300 ms)
13691369
minSlack = serviceConf.ibra_minslack_greaterthan200ms;
13701370
maxSlack = serviceConf.ibra_maxslack_greaterthan200ms;
13711371
}
@@ -1995,11 +1995,16 @@ PlayerLeaveCode ConnectionManager::disconnectPlayer(Int slot) {
19951995

19961996
if (slot == m_packetRouterSlot) {
19971997
Int index = 0;
1998-
while ((index < (MAX_SLOTS-1)) && (m_packetRouterFallback[index] != m_packetRouterSlot)) {
1998+
while ((index < MAX_SLOTS) && (m_packetRouterFallback[index] != m_packetRouterSlot)) {
19991999
++index;
20002000
}
20012001
++index;
2002-
m_packetRouterSlot = m_packetRouterFallback[index];
2002+
if (index < MAX_SLOTS) {
2003+
m_packetRouterSlot = m_packetRouterFallback[index];
2004+
} else {
2005+
DEBUG_LOG(("ConnectionManager::disconnectPlayer - packet router had no valid fallback, defaulting to local slot %d", m_localSlot));
2006+
m_packetRouterSlot = m_localSlot;
2007+
}
20032008
DEBUG_LOG(("Packet router left. New packet router is slot %d", m_packetRouterSlot));
20042009
retval = PLAYERLEAVECODE_PACKETROUTER;
20052010
}
@@ -2701,11 +2706,14 @@ void ConnectionManager::sendSingleFrameToPlayer(UnsignedInt playerID, UnsignedIn
27012706

27022707
UnsignedInt ConnectionManager::getNextPacketRouterSlot(UnsignedInt playerID) {
27032708
Int index = 0;
2704-
while ((index < (MAX_SLOTS-1)) && (m_packetRouterFallback[index] != playerID)) {
2709+
while ((index < MAX_SLOTS) && (m_packetRouterFallback[index] != playerID)) {
27052710
++index;
27062711
}
27072712
++index;
2708-
return m_packetRouterFallback[index];
2713+
if (index < MAX_SLOTS) {
2714+
return m_packetRouterFallback[index];
2715+
}
2716+
return MAX_SLOTS; // No valid next packet router; caller checks for >= MAX_SLOTS
27092717
}
27102718

27112719
void ConnectionManager::requestFrameDataResend(Int playerID, UnsignedInt frame) {

0 commit comments

Comments
 (0)