Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
20 changes: 14 additions & 6 deletions Packet++/src/BgpLayer.cpp
Copy link
Owner

Choose a reason for hiding this comment

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

Can you add the packet data that caused this issue to our regression tests, the same way it's done in this PR?

Copy link
Author

Choose a reason for hiding this comment

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

Sure, will do!

Original file line number Diff line number Diff line change
Expand Up @@ -744,13 +744,21 @@ namespace pcpp

if (newNlriDataLen > curNlriDataLen)
{
bool res = extendLayer(sizeof(bgp_common_header) + 2 * sizeof(uint16_t) + curWithdrawnRoutesDataLen +
curPathAttributesDataLen,
newNlriDataLen - curNlriDataLen);
if (!res)
try
{
PCPP_LOG_ERROR("Couldn't extend BGP update layer to include the additional NLRI data");
return res;
bool res = extendLayer(sizeof(bgp_common_header) + 2 * sizeof(uint16_t) + curWithdrawnRoutesDataLen +
curPathAttributesDataLen,
newNlriDataLen - curNlriDataLen);
if (!res)
{
PCPP_LOG_ERROR("Couldn't extend BGP update layer to include the additional NLRI data");
return res;
}
}
catch (const std::length_error& e)
{
PCPP_LOG_ERROR("Failed to extend BGP update layer: " << e.what());
return false;
}
}
else if (newNlriDataLen < curNlriDataLen)
Expand Down
7 changes: 7 additions & 0 deletions Packet++/src/RawPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ namespace pcpp

void RawPacket::insertData(int atIndex, const uint8_t* dataToInsert, size_t dataToInsertLen)
{
// Check for overflow in the new length
if ((size_t)m_RawDataLen + dataToInsertLen < (size_t)m_RawDataLen)
{
throw std::length_error(
"RawPacket::insertData: dataToInsertLen causes overflow in the new length calculation");
}

// memmove copies data as if there was an intermediate buffer in between - so it allows for copying processes on
// overlapping src/dest ptrs if insertData is called with atIndex == m_RawDataLen, then no data is being moved.
// The data of the raw packet is still extended by dataToInsertLen
Expand Down
Loading