Browse Source

Fix potential out of bounds access

Matt Coburn 4 years ago
parent
commit
aef654c6c1
1 changed files with 6 additions and 5 deletions
  1. 6 5
      Source/Native/enet.h

+ 6 - 5
Source/Native/enet.h

@@ -2761,9 +2761,9 @@ static int enet_protocol_check_outgoing_commands(ENetHost* host, ENetPeer* peer)
 	ENetBuffer* buffer = &host->buffers[host->bufferCount];
 	ENetBuffer* buffer = &host->buffers[host->bufferCount];
 	ENetOutgoingCommand* outgoingCommand;
 	ENetOutgoingCommand* outgoingCommand;
 	ENetListIterator currentCommand;
 	ENetListIterator currentCommand;
-	ENetChannel* channel;
-	uint16_t reliableWindow;
-	size_t commandSize;
+	ENetChannel* channel = NULL;
+	uint16_t reliableWindow = 0;
+	size_t commandSize = 0;
 	int windowExceeded = 0, windowWrap = 0, canPing = 1;
 	int windowExceeded = 0, windowWrap = 0, canPing = 1;
 	currentCommand = enet_list_begin(&peer->outgoingCommands);
 	currentCommand = enet_list_begin(&peer->outgoingCommands);
 
 
@@ -3150,7 +3150,7 @@ int enet_peer_throttle(ENetPeer* peer, uint32_t rtt) {
 }
 }
 
 
 int enet_peer_send(ENetPeer* peer, uint8_t channelID, ENetPacket* packet) {
 int enet_peer_send(ENetPeer* peer, uint8_t channelID, ENetPacket* packet) {
-	ENetChannel* channel = &peer->channels[channelID];
+	ENetChannel* channel;
 	ENetProtocol command;
 	ENetProtocol command;
 	size_t fragmentLength;
 	size_t fragmentLength;
 
 
@@ -3158,7 +3158,8 @@ int enet_peer_send(ENetPeer* peer, uint8_t channelID, ENetPacket* packet) {
 		ENET_LOG_ERROR("Failed sending data. Peer is not connected, the channel is above the maximum channels supported or the payload length is too large.");
 		ENET_LOG_ERROR("Failed sending data. Peer is not connected, the channel is above the maximum channels supported or the payload length is too large.");
 		return -1;
 		return -1;
 	}
 	}
-
+	
+	channel = &peer->channels[channelID];
 	fragmentLength = peer->mtu - sizeof(ENetProtocolHeader) - sizeof(ENetProtocolSendFragment) - sizeof(ENetProtocolAcknowledge);
 	fragmentLength = peer->mtu - sizeof(ENetProtocolHeader) - sizeof(ENetProtocolSendFragment) - sizeof(ENetProtocolAcknowledge);
 
 
 	if (peer->host->checksumCallback != NULL)
 	if (peer->host->checksumCallback != NULL)