Skip to content

Commit 842dc17

Browse files
authored
Merge pull request #76 from ikpil/master
fix missing channelID bounds check
2 parents 90471c7 + 09cc4ff commit 842dc17

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ x64/
1010

1111
# Other
1212
.DS_store
13+
.idea
1314

1415
# local build scripts
1516
build.sh

include/enet.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3654,14 +3654,16 @@ extern "C" {
36543654
* @retval < 0 on failure
36553655
*/
36563656
int enet_peer_send(ENetPeer *peer, enet_uint8 channelID, ENetPacket *packet) {
3657-
ENetChannel *channel = &peer->channels[channelID];
3657+
ENetChannel *channel = NULL;
36583658
ENetProtocol command;
36593659
size_t fragmentLength;
36603660

36613661
if (peer->state != ENET_PEER_STATE_CONNECTED || channelID >= peer->channelCount || packet->dataLength > peer->host->maximumPacketSize) {
36623662
return -1;
36633663
}
36643664

3665+
channel = &peer->channels[channelID];
3666+
36653667
fragmentLength = peer->mtu - sizeof(ENetProtocolHeader) - sizeof(ENetProtocolSendFragment);
36663668
if (peer->host->checksum != NULL) {
36673669
fragmentLength -= sizeof(enet_uint32);
@@ -4141,7 +4143,12 @@ extern "C" {
41414143
}
41424144

41434145
void enet_peer_setup_outgoing_command(ENetPeer *peer, ENetOutgoingCommand *outgoingCommand) {
4144-
ENetChannel *channel = &peer->channels[outgoingCommand->command.header.channelID];
4146+
ENetChannel *channel = NULL;
4147+
4148+
if (outgoingCommand->command.header.channelID < peer->channelCount) {
4149+
channel = &peer->channels[outgoingCommand->command.header.channelID];
4150+
}
4151+
41454152
peer->outgoingDataTotal += enet_protocol_command_size(outgoingCommand->command.header.command) + outgoingCommand->fragmentLength;
41464153

41474154
if (outgoingCommand->command.header.channelID == 0xFF) {

0 commit comments

Comments
 (0)