-
Notifications
You must be signed in to change notification settings - Fork 98
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
Added: out of bounds checks for RakNet arrays #905
Open
uifdev
wants to merge
2
commits into
openmultiplayer:master
Choose a base branch
from
uifdev:raknet-array-checks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -317,8 +317,9 @@ enum LegacyClientVersion | |
IPlayer* RakNetLegacyNetwork::OnPeerConnect(RakNet::RPCParameters* rpcParams, bool isNPC, StringView serial, uint32_t version, StringView versionName, uint32_t challenge, StringView name, bool isUsingOfficialClient) | ||
{ | ||
const RakNet::PlayerID rid = rpcParams->sender; | ||
const RakNet::PlayerIndex senderId = rpcParams->senderIndex; | ||
|
||
if (playerFromRakIndex[rpcParams->senderIndex]) | ||
if (senderId < 0 || senderId >= PLAYER_POOL_SIZE || playerFromRakIndex[senderId]) | ||
{ | ||
// Connection already exists | ||
return nullptr; | ||
|
@@ -369,7 +370,7 @@ IPlayer* RakNetLegacyNetwork::OnPeerConnect(RakNet::RPCParameters* rpcParams, bo | |
return nullptr; | ||
} | ||
|
||
playerFromRakIndex[rpcParams->senderIndex] = newConnectionResult.second; | ||
playerFromRakIndex[senderId] = newConnectionResult.second; | ||
|
||
return newConnectionResult.second; | ||
} | ||
|
@@ -451,7 +452,9 @@ void RakNetLegacyNetwork::OnPlayerConnect(RakNet::RPCParameters* rpcParams, void | |
|
||
network->networkEventDispatcher.dispatch(&NetworkEventHandler::onPeerConnect, *newPeer); | ||
|
||
network->playerRemoteSystem[newPeer->getID()] = remoteSystem; | ||
auto poolID = newPeer->getID(); | ||
if(poolID >= 0 && poolID < PLAYER_POOL_SIZE) network->playerRemoteSystem[poolID] = remoteSystem; | ||
|
||
return; | ||
} | ||
} | ||
|
@@ -517,15 +520,19 @@ void RakNetLegacyNetwork::OnNPCConnect(RakNet::RPCParameters* rpcParams, void* e | |
|
||
void RakNetLegacyNetwork::OnRakNetDisconnect(RakNet::PlayerIndex rid, PeerDisconnectReason reason) | ||
{ | ||
if(rid < 0 || rid >= PLAYER_POOL_SIZE) return; | ||
|
||
IPlayer* player = playerFromRakIndex[rid]; | ||
playerFromRakIndex[rid] = nullptr; | ||
|
||
if (!player) | ||
{ | ||
return; | ||
} | ||
|
||
playerFromRakIndex[rid] = nullptr; | ||
playerRemoteSystem[player->getID()] = nullptr; | ||
auto poolID = player->getID(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same issue here |
||
if(poolID >= 0 && poolID < PLAYER_POOL_SIZE) playerRemoteSystem[poolID] = nullptr; | ||
|
||
networkEventDispatcher.dispatch(&NetworkEventHandler::onPeerDisconnect, *player, reason); | ||
} | ||
|
||
|
@@ -535,7 +542,7 @@ void RakNetLegacyNetwork::RPCHook(RakNet::RPCParameters* rpcParams, void* extra) | |
RakNetLegacyNetwork* network = reinterpret_cast<RakNetLegacyNetwork*>(extra); | ||
const RakNet::PlayerIndex senderId = rpcParams->senderIndex; | ||
|
||
if (senderId >= network->playerFromRakIndex.size()) | ||
if (senderId < 0 || senderId >= PLAYER_POOL_SIZE) | ||
{ | ||
return; | ||
} | ||
|
@@ -887,7 +894,7 @@ void RakNetLegacyNetwork::onTick(Microseconds elapsed, TimePoint now) | |
{ | ||
for (RakNet::Packet* pkt = rakNetServer.Receive(); pkt; pkt = rakNetServer.Receive()) | ||
{ | ||
if (pkt->playerIndex >= playerFromRakIndex.size()) | ||
if (pkt->playerIndex < 0 || pkt->playerIndex >= PLAYER_POOL_SIZE) | ||
{ | ||
rakNetServer.DeallocatePacket(pkt); | ||
continue; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -361,7 +361,10 @@ class RakNetLegacyNetwork final : public Network, public CoreEventHandler, publi | |
|
||
unsigned getPing(const IPlayer& peer) override | ||
{ | ||
auto remoteSystem = playerRemoteSystem[peer.getID()]; | ||
auto poolID = peer.getID(); | ||
if(poolID < 0 || poolID >= PLAYER_POOL_SIZE) return -1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here |
||
|
||
auto remoteSystem = playerRemoteSystem[poolID]; | ||
if (remoteSystem == nullptr) | ||
{ | ||
return -1; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't make sense to me - if a new peer was just created successfully (non null) then their ID should be valid