mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Shared/Networking: Fix buffer overflow in Socket handling
Fix a buffer overflow caused by Boost trying to store too much data in a buffer too small.
(cherry picked from commit cdf6c88462)
This commit is contained in:
@@ -81,6 +81,14 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// Ensures there's "some" free space, make sure to call Normalize() before this
|
||||
void EnsureFreeSpace()
|
||||
{
|
||||
// Double the size of the buffer if it's already full
|
||||
if (GetRemainingSpace() == 0)
|
||||
_storage.resize(_storage.size() * 2);
|
||||
}
|
||||
|
||||
void Write(void const* data, std::size_t size)
|
||||
{
|
||||
if (size)
|
||||
|
||||
@@ -92,7 +92,8 @@ public:
|
||||
return;
|
||||
|
||||
_readBuffer.Normalize();
|
||||
_socket.async_read_some(boost::asio::buffer(_readBuffer.GetWritePointer(), READ_BLOCK_SIZE),
|
||||
_readBuffer.EnsureFreeSpace();
|
||||
_socket.async_read_some(boost::asio::buffer(_readBuffer.GetWritePointer(), _readBuffer.GetRemainingSpace()),
|
||||
std::bind(&Socket<T>::ReadHandlerInternal, this->shared_from_this(), std::placeholders::_1, std::placeholders::_2));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user