Skip to content
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
9 changes: 9 additions & 0 deletions Packet++/header/SomeIpSdLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,14 @@ class SomeIpSdLayer : public SomeIpLayer
*/
static bool isSomeIpSdPort(uint16_t port) { return port == 30490; }

/**
* The static method makes validation of input data
* @param[in] data The pointer to the beginning of byte stream of IP packet
* @param[in] dataLen The length of byte stream
* @return True if the data is valid and can represent the packet
*/
static bool isDataValid(const uint8_t* data, size_t dataLen);

/**
* Get the Flags of the layer
* @return uint8_t Flags
Expand Down Expand Up @@ -759,6 +767,7 @@ class SomeIpSdLayer : public SomeIpLayer
bool addOptionIndex(uint32_t indexEntry, uint32_t indexOffset);
OptionPtr parseOption(SomeIpSdOption::OptionType type, size_t offset) const;

static size_t getLenEntries(const uint8_t* data);
size_t getLenEntries() const;
size_t getLenOptions() const;
void setLenEntries(uint32_t length);
Expand Down
2 changes: 1 addition & 1 deletion Packet++/src/SomeIpLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Layer* SomeIpLayer::parseSomeIpLayer(uint8_t *data, size_t dataLen, Layer* prevL
return new PayloadLayer(data, dataLen, prevLayer, packet);
}

if (be16toh(hdr->serviceID) == 0xFFFF && be16toh(hdr->methodID) == 0x8100)
if (be16toh(hdr->serviceID) == 0xFFFF && be16toh(hdr->methodID) == 0x8100 && SomeIpSdLayer::isDataValid(data, dataLen))
{
return new SomeIpSdLayer(data, dataLen, prevLayer, packet);
}
Expand Down
21 changes: 20 additions & 1 deletion Packet++/src/SomeIpSdLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,20 @@ uint32_t SomeIpSdLayer::addEntry(const SomeIpSdEntry &entry)
return getNumEntries() - 1;
}

bool SomeIpSdLayer::isDataValid(const uint8_t* data, size_t dataLen)
{
if (!data)
return false;

if (dataLen < (sizeof(someipsdhdr) + sizeof(uint32_t)))
return false;

if (dataLen < (sizeof(someipsdhdr) + sizeof(uint32_t) + getLenEntries(data)))
return false;

return true;
}

uint32_t SomeIpSdLayer::countOptions()
{
size_t offsetOption = sizeof(someipsdhdr) + sizeof(uint32_t) + getLenEntries() + sizeof(uint32_t);
Expand Down Expand Up @@ -768,7 +782,12 @@ SomeIpSdLayer::OptionPtr SomeIpSdLayer::parseOption(SomeIpSdOption::OptionType t

size_t SomeIpSdLayer::getLenEntries() const
{
return be32toh(*((uint32_t *)(m_Data + sizeof(someipsdhdr))));
return getLenEntries(m_Data);
}

size_t SomeIpSdLayer::getLenEntries(const uint8_t* data)
{
return be32toh(*((uint32_t *)(data + sizeof(someipsdhdr))));
}

size_t SomeIpSdLayer::getLenOptions() const
Expand Down
Binary file not shown.