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

Added bounds checking. #1939

Open
wants to merge 1 commit into
base: master
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 4 additions & 0 deletions libi2pd/NetDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,10 @@ 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 * 32))
Copy link
Member

@r4sas r4sas Jul 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use constant instead of 32.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the constant name for a router identity hash? I don't see anything already defined in any headers.

I just copied the values from with-in the for() loop below it.

                for (int i = 0; i < num; i++)
                {
                        const uint8_t * router = buf + 33 + i*32;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no suggestions are given, will add new IDENTITY_HASH_SIZE constant to Identity.h.

return;

// try responses
for (int i = 0; i < num; i++)
{
Expand Down