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

Fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=64110 #1236

Merged
merged 2 commits into from
Nov 14, 2023
Merged
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
20 changes: 20 additions & 0 deletions Packet++/header/GreLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,16 @@ namespace pcpp
*/
bool unsetKey();

/**
* A static method that validates the input data
* @param[in] data The pointer to the beginning of a byte stream of an GREv0 layer
* @param[in] dataLen The length of the byte stream
* @return True if the data is valid and can represent an GREv0 layer
*/
static inline bool isDataValid(const uint8_t* data, size_t dataLen)
{
return data && dataLen >= sizeof(gre_basic_header);
}

// implement abstract methods

Expand Down Expand Up @@ -350,6 +360,16 @@ namespace pcpp
*/
bool unsetAcknowledgmentNum();

/**
* A static method that validates the input data
* @param[in] data The pointer to the beginning of a byte stream of an GREv1 layer
* @param[in] dataLen The length of the byte stream
* @return True if the data is valid and can represent an GREv1 layer
*/
static inline bool isDataValid(const uint8_t* data, size_t dataLen)
{
return data && dataLen >= sizeof(gre1_header);
}

// implement abstract methods

Expand Down
4 changes: 2 additions & 2 deletions Packet++/src/IPv4Layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ void IPv4Layer::parseNextLayer()
break;
case PACKETPP_IPPROTO_GRE:
greVer = GreLayer::getGREVersion(payload, payloadLen);
if (greVer == GREv0)
if (greVer == GREv0 && GREv0Layer::isDataValid(payload, payloadLen))
m_NextLayer = new GREv0Layer(payload, payloadLen, this, m_Packet);
else if (greVer == GREv1)
else if (greVer == GREv1 && GREv1Layer::isDataValid(payload, payloadLen))
m_NextLayer = new GREv1Layer(payload, payloadLen, this, m_Packet);
else
m_NextLayer = new PayloadLayer(payload, payloadLen, this, m_Packet);
Expand Down
4 changes: 2 additions & 2 deletions Packet++/src/IPv6Layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ void IPv6Layer::parseNextLayer()
case PACKETPP_IPPROTO_GRE:
{
ProtocolType greVer = GreLayer::getGREVersion(payload, payloadLen);
if (greVer == GREv0)
if (greVer == GREv0 && GREv0Layer::isDataValid(payload, payloadLen))
m_NextLayer = new GREv0Layer(payload, payloadLen, this, m_Packet);
else if (greVer == GREv1)
else if (greVer == GREv1 && GREv1Layer::isDataValid(payload, payloadLen))
m_NextLayer = new GREv1Layer(payload, payloadLen, this, m_Packet);
else
m_NextLayer = new PayloadLayer(payload, payloadLen, this, m_Packet);
Expand Down