NetPlay: Fixed crash that occurred when bytes were > 127. Signed chars ended up becoming huge unsigned numbers, triggering the maximum message length and closing the connection.

This commit is contained in:
Souryo 2016-01-28 20:55:48 -05:00
parent c772d4d0d5
commit a681b4992c
2 changed files with 4 additions and 4 deletions

View File

@ -15,7 +15,7 @@ GameConnection::GameConnection(shared_ptr<Socket> socket, shared_ptr<ClientConne
void GameConnection::ReadSocket()
{
int bytesReceived = _socket->Recv(_readBuffer + _readPosition, 0x40000 - _readPosition, 0);
int bytesReceived = _socket->Recv((char*)_readBuffer + _readPosition, 0x40000 - _readPosition, 0);
if(bytesReceived > 0) {
_readPosition += bytesReceived;
}
@ -25,7 +25,7 @@ bool GameConnection::ExtractMessage(void *buffer, uint32_t &messageLength)
{
messageLength = _readBuffer[0] | (_readBuffer[1] << 8) | (_readBuffer[2] << 16) | (_readBuffer[3] << 24);
if(messageLength > 100000) {
if(messageLength > 1000000) {
std::cout << "Invalid data received, closing connection" << std::endl;
_socket->Close();
return false;

View File

@ -11,8 +11,8 @@ class GameConnection
protected:
shared_ptr<Socket> _socket;
shared_ptr<ClientConnectionData> _connectionData;
char _readBuffer[0x40000];
char _messageBuffer[0x40000];
uint8_t _readBuffer[0x40000];
uint8_t _messageBuffer[0x40000];
int _readPosition = 0;
SimpleLock _socketLock;