Skip to content

Commit

Permalink
Fix oss-fuzz issue 64110 (#1236)
Browse files Browse the repository at this point in the history
  • Loading branch information
sashashura authored Nov 14, 2023
1 parent 9814366 commit a0ecc6d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
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

0 comments on commit a0ecc6d

Please sign in to comment.