Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sashashura committed Nov 12, 2023
1 parent 0c95dfb commit 05001ca
Show file tree
Hide file tree
Showing 3 changed files with 36 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
10 changes: 8 additions & 2 deletions Packet++/src/IPv4Layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,15 @@ void IPv4Layer::parseNextLayer()
case PACKETPP_IPPROTO_GRE:
greVer = GreLayer::getGREVersion(payload, payloadLen);
if (greVer == GREv0)
m_NextLayer = new GREv0Layer(payload, payloadLen, this, m_Packet);
{
if (GREv0Layer::isDataValid(payload, payloadLen))
m_NextLayer = new GREv0Layer(payload, payloadLen, this, m_Packet);
}
else if (greVer == GREv1)
m_NextLayer = new GREv1Layer(payload, payloadLen, this, m_Packet);
{
if (GREv1Layer::isDataValid(payload, payloadLen))
m_NextLayer = new GREv1Layer(payload, payloadLen, this, m_Packet);
}
else
m_NextLayer = new PayloadLayer(payload, payloadLen, this, m_Packet);
break;
Expand Down
10 changes: 8 additions & 2 deletions Packet++/src/IPv6Layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,15 @@ void IPv6Layer::parseNextLayer()
{
ProtocolType greVer = GreLayer::getGREVersion(payload, payloadLen);
if (greVer == GREv0)
m_NextLayer = new GREv0Layer(payload, payloadLen, this, m_Packet);
{
if (GREv0Layer::isDataValid(payload, payloadLen))
m_NextLayer = new GREv0Layer(payload, payloadLen, this, m_Packet);
}
else if (greVer == GREv1)
m_NextLayer = new GREv1Layer(payload, payloadLen, this, m_Packet);
{
if (GREv1Layer::isDataValid(payload, payloadLen))
m_NextLayer = new GREv1Layer(payload, payloadLen, this, m_Packet);
}
else
m_NextLayer = new PayloadLayer(payload, payloadLen, this, m_Packet);
break;
Expand Down

0 comments on commit 05001ca

Please sign in to comment.