mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-22 00:59:08 +01:00
check max RouterInfo size
This commit is contained in:
parent
f20391d460
commit
a723405fb0
2 changed files with 17 additions and 10 deletions
|
@ -695,7 +695,7 @@ namespace transport
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto size = bufbe16toh (buf.data () + 1);
|
auto size = bufbe16toh (buf.data () + 1);
|
||||||
if (size > buf.size () - 3)
|
if (size > buf.size () - 3 || size > i2p::data::MAX_RI_BUFFER_SIZE + 1)
|
||||||
{
|
{
|
||||||
LogPrint (eLogError, "NTCP2: Unexpected RouterInfo size ", size, " in SessionConfirmed");
|
LogPrint (eLogError, "NTCP2: Unexpected RouterInfo size ", size, " in SessionConfirmed");
|
||||||
Terminate ();
|
Terminate ();
|
||||||
|
@ -960,6 +960,8 @@ namespace transport
|
||||||
case eNTCP2BlkRouterInfo:
|
case eNTCP2BlkRouterInfo:
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "NTCP2: RouterInfo flag=", (int)frame[offset]);
|
LogPrint (eLogDebug, "NTCP2: RouterInfo flag=", (int)frame[offset]);
|
||||||
|
if (size <= i2p::data::MAX_RI_BUFFER_SIZE + 1)
|
||||||
|
{
|
||||||
auto newRi = i2p::data::netdb.AddRouterInfo (frame + offset + 1, size - 1);
|
auto newRi = i2p::data::netdb.AddRouterInfo (frame + offset + 1, size - 1);
|
||||||
if (newRi)
|
if (newRi)
|
||||||
{
|
{
|
||||||
|
@ -968,6 +970,9 @@ namespace transport
|
||||||
// peer's RouterInfo update
|
// peer's RouterInfo update
|
||||||
SetRemoteIdentity (newRi->GetIdentity ());
|
SetRemoteIdentity (newRi->GetIdentity ());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LogPrint (eLogInfo, "NTCP2: RouterInfo block is too long ", size);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case eNTCP2BlkI2NPMessage:
|
case eNTCP2BlkI2NPMessage:
|
||||||
|
|
|
@ -2937,13 +2937,15 @@ namespace transport
|
||||||
i2p::data::GzipInflator inflator;
|
i2p::data::GzipInflator inflator;
|
||||||
uint8_t uncompressed[i2p::data::MAX_RI_BUFFER_SIZE];
|
uint8_t uncompressed[i2p::data::MAX_RI_BUFFER_SIZE];
|
||||||
size_t uncompressedSize = inflator.Inflate (buf + 2, size - 2, uncompressed, i2p::data::MAX_RI_BUFFER_SIZE);
|
size_t uncompressedSize = inflator.Inflate (buf + 2, size - 2, uncompressed, i2p::data::MAX_RI_BUFFER_SIZE);
|
||||||
if (uncompressedSize && uncompressedSize < i2p::data::MAX_RI_BUFFER_SIZE)
|
if (uncompressedSize && uncompressedSize <= i2p::data::MAX_RI_BUFFER_SIZE)
|
||||||
ri = std::make_shared<i2p::data::RouterInfo>(uncompressed, uncompressedSize);
|
ri = std::make_shared<i2p::data::RouterInfo>(uncompressed, uncompressedSize);
|
||||||
else
|
else
|
||||||
LogPrint (eLogInfo, "SSU2: RouterInfo decompression failed ", uncompressedSize);
|
LogPrint (eLogInfo, "SSU2: RouterInfo decompression failed ", uncompressedSize);
|
||||||
}
|
}
|
||||||
else
|
else if (size <= i2p::data::MAX_RI_BUFFER_SIZE + 2)
|
||||||
ri = std::make_shared<i2p::data::RouterInfo>(buf + 2, size - 2);
|
ri = std::make_shared<i2p::data::RouterInfo>(buf + 2, size - 2);
|
||||||
|
else
|
||||||
|
LogPrint (eLogInfo, "SSU2: RouterInfo is too long ", size);
|
||||||
return ri;
|
return ri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue