mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
correct concatenation of long I2CP messages
This commit is contained in:
parent
37fc21f3cf
commit
4d2b535b04
16
I2CP.cpp
16
I2CP.cpp
@ -164,25 +164,34 @@ namespace client
|
||||
Terminate ();
|
||||
else
|
||||
{
|
||||
size_t offset = 0;
|
||||
size_t offset = 0; // from m_Buffer
|
||||
if (m_NextMessage)
|
||||
{
|
||||
if (m_NextMessageOffset + bytes_transferred <= m_NextMessageLen)
|
||||
{
|
||||
memcpy (m_NextMessage + m_NextMessageOffset, m_Buffer, bytes_transferred);
|
||||
m_NextMessageOffset += bytes_transferred;
|
||||
offset = bytes_transferred;
|
||||
}
|
||||
else
|
||||
{
|
||||
// m_NextMessage complete
|
||||
offset = m_NextMessageLen - m_NextMessageOffset;
|
||||
memcpy (m_NextMessage + m_NextMessageOffset, m_Buffer, offset);
|
||||
HandleNextMessage (m_NextMessage);
|
||||
delete[] m_NextMessage;
|
||||
m_NextMessage = nullptr;
|
||||
}
|
||||
}
|
||||
while (offset < bytes_transferred)
|
||||
{
|
||||
auto msgLen = bufbe32toh (m_Buffer + offset + I2CP_HEADER_LENGTH_OFFSET) + I2CP_HEADER_SIZE;
|
||||
if (msgLen > 0xFFFF) // 64K
|
||||
{
|
||||
LogPrint (eLogError, "I2CP: message length ", msgLen, " exceeds 64K. Terminated");
|
||||
Terminate ();
|
||||
return;
|
||||
}
|
||||
if (msgLen <= bytes_transferred - offset)
|
||||
{
|
||||
HandleNextMessage (m_Buffer + offset);
|
||||
@ -217,6 +226,11 @@ namespace client
|
||||
m_Destination->Stop ();
|
||||
m_Destination = nullptr;
|
||||
}
|
||||
if (m_Socket)
|
||||
{
|
||||
m_Socket->close ();
|
||||
m_Socket = nullptr;
|
||||
}
|
||||
m_Owner.RemoveSession (GetSessionID ());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user