Browse Source

limit SSU message size to 32K

pull/1258/head
orignal 6 years ago
parent
commit
b84f74c167
  1. 4
      libi2pd/SSUData.cpp
  2. 8
      libi2pd/SSUSession.cpp
  3. 1
      libi2pd/SSUSession.h

4
libi2pd/SSUData.cpp

@ -320,7 +320,7 @@ namespace transport @@ -320,7 +320,7 @@ namespace transport
uint8_t * msgBuf = msg->GetSSUHeader ();
uint32_t fragmentNum = 0;
while (len > 0)
while (len > 0 && fragmentNum <= 127)
{
Fragment * fragment = new Fragment;
fragment->fragmentNum = fragmentNum;
@ -332,7 +332,7 @@ namespace transport @@ -332,7 +332,7 @@ namespace transport
payload++;
htobe32buf (payload, msgID);
payload += 4;
bool isLast = (len <= payloadSize);
bool isLast = (len <= payloadSize) || fragmentNum == 127; // 127 fragments max
size_t size = isLast ? len : payloadSize;
uint32_t fragmentInfo = (fragmentNum << 17);
if (isLast)

8
libi2pd/SSUSession.cpp

@ -929,7 +929,13 @@ namespace transport @@ -929,7 +929,13 @@ namespace transport
if (m_State == eSessionStateEstablished)
{
for (const auto& it: msgs)
if (it) m_Data.Send (it);
if (it)
{
if (it->GetLength () <= SSU_MAX_I2NP_MESSAGE_SIZE)
m_Data.Send (it);
else
LogPrint (eLogError, "SSU: I2NP message of size ", it->GetLength (), " can't be sent. Dropped");
}
}
}

1
libi2pd/SSUSession.h

@ -28,6 +28,7 @@ namespace transport @@ -28,6 +28,7 @@ namespace transport
const int SSU_CONNECT_TIMEOUT = 5; // 5 seconds
const int SSU_TERMINATION_TIMEOUT = 330; // 5.5 minutes
const int SSU_CLOCK_SKEW = 60; // in seconds
const size_t SSU_MAX_I2NP_MESSAGE_SIZE = 32768;
// payload types (4 bits)
const uint8_t PAYLOAD_TYPE_SESSION_REQUEST = 0;

Loading…
Cancel
Save