mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-22 10:05:32 +01:00
Core/Networking: Fixed possible buffer overflows in WorldSocket::WritePacketToBuffer
Closes #28370
This commit is contained in:
@@ -203,10 +203,11 @@ bool WorldSocket::Update()
|
||||
MessageBuffer buffer(_sendBufferSize);
|
||||
while (_bufferQueue.Dequeue(queued))
|
||||
{
|
||||
uint32 packetSize = queued->size();
|
||||
uint32 packetSize = queued->size() + 2 /*opcode*/;
|
||||
if (packetSize > MinSizeForCompression && queued->NeedsEncryption())
|
||||
packetSize = compressBound(packetSize) + sizeof(CompressedWorldPacket);
|
||||
packetSize = deflateBound(_compressionStream, packetSize) + sizeof(CompressedWorldPacket);
|
||||
|
||||
// Flush current buffer if too small for next packet
|
||||
if (buffer.GetRemainingSpace() < packetSize + sizeof(PacketHeader))
|
||||
{
|
||||
QueuePacket(std::move(buffer));
|
||||
@@ -215,7 +216,7 @@ bool WorldSocket::Update()
|
||||
|
||||
if (buffer.GetRemainingSpace() >= packetSize + sizeof(PacketHeader))
|
||||
WritePacketToBuffer(*queued, buffer);
|
||||
else // single packet larger than 4096 bytes
|
||||
else // single packet larger than _sendBufferSize
|
||||
{
|
||||
MessageBuffer packetBuffer(packetSize + sizeof(PacketHeader));
|
||||
WritePacketToBuffer(*queued, packetBuffer);
|
||||
|
||||
Reference in New Issue
Block a user