From dc357c923921aa3b7605ec8201a2f0c001d717a4 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 21 May 2019 18:55:54 +0100 Subject: [PATCH] Fix length checks in network packet send/recv binary --- src/network/core/packet.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/network/core/packet.cpp b/src/network/core/packet.cpp index efdbe2b184..d651233d25 100644 --- a/src/network/core/packet.cpp +++ b/src/network/core/packet.cpp @@ -168,7 +168,7 @@ void Packet::Send_string(const char *data) void Packet::Send_binary(const char *data, const size_t size) { assert(data != nullptr); - assert(size < MAX_CMD_TEXT_LENGTH); + assert(this->size + size <= SHRT_MAX); memcpy(&this->buffer[this->size], data, size); this->size += (PacketSize) size; } @@ -351,8 +351,7 @@ void Packet::Recv_string(std::string &buffer, StringValidationSettings settings) */ void Packet::Recv_binary(char *buffer, size_t size) { - /* Don't allow reading from a closed socket */ - if (cs->HasClientQuit()) return; + if (!this->CanReadFromPacket(size)) return; memcpy(buffer, &this->buffer[this->pos], size); this->pos += (PacketSize) size; @@ -365,8 +364,7 @@ void Packet::Recv_binary(char *buffer, size_t size) */ void Packet::Recv_binary(std::string &buffer, size_t size) { - /* Don't allow reading from a closed socket */ - if (cs->HasClientQuit()) return; + if (!this->CanReadFromPacket(size)) return; buffer.assign((const char *) &this->buffer[this->pos], size); this->pos += (PacketSize) size;