Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bounds checking and related changes. #1941

Open
wants to merge 7 commits into
base: openssl
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion libi2pd/Identity.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ namespace i2p
{
namespace data
{
typedef Tag<32> IdentHash;
const uint8_t IDENTITY_HASH_SIZE = 32;

typedef Tag<IDENTITY_HASH_SIZE> IdentHash;
inline std::string GetIdentHashAbbreviation (const IdentHash& ident)
{
return ident.ToBase64 ().substr (0, 4);
Expand Down
8 changes: 8 additions & 0 deletions libi2pd/LeaseSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,10 @@ namespace data
size_t LeaseSet2::ReadStandardLS2TypeSpecificPart (const uint8_t * buf, size_t len)
{
size_t offset = 0;

if(offset + 2 > len) // AKA (len < 2)
return 0;

// properties
uint16_t propertiesLen = bufbe16toh (buf + offset); offset += 2;
offset += propertiesLen; // skip for now. TODO: implement properties
Expand Down Expand Up @@ -448,6 +452,10 @@ namespace data
size_t LeaseSet2::ReadMetaLS2TypeSpecificPart (const uint8_t * buf, size_t len)
{
size_t offset = 0;

if(offset + 2 > len) // AKA (len < 2)
return 0;

// properties
uint16_t propertiesLen = bufbe16toh (buf + offset); offset += 2;
offset += propertiesLen; // skip for now. TODO: implement properties
Expand Down
8 changes: 6 additions & 2 deletions libi2pd/NetDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,12 +950,16 @@ namespace data
else if(!m_FloodfillBootstrap)
LogPrint (eLogWarning, "NetDb: Requested destination for ", key, " not found");

// All peers hashs in buffer?
if(msg->GetPayloadLength() < (size_t) (33 + num * IDENTITY_HASH_SIZE))
return;

// try responses
for (int i = 0; i < num; i++)
{
const uint8_t * router = buf + 33 + i*32;
const uint8_t * router = buf + 33 + i*IDENTITY_HASH_SIZE;
char peerHash[48];
int l1 = i2p::data::ByteStreamToBase64 (router, 32, peerHash, 48);
int l1 = i2p::data::ByteStreamToBase64 (router, IDENTITY_HASH_SIZE, peerHash, 48);
peerHash[l1] = 0;
LogPrint (eLogDebug, "NetDb: ", i, ": ", peerHash);

Expand Down