Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sashashura committed Nov 15, 2023
1 parent 34e4b62 commit d152bb2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions Packet++/header/SomeIpSdLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ class SomeIpSdLayer : public SomeIpLayer

static size_t getLenEntries(const uint8_t* data);
size_t getLenEntries() const;
static size_t getLenOptions(const uint8_t* data);
size_t getLenOptions() const;
void setLenEntries(uint32_t length);
void setLenOptions(uint32_t length);
Expand Down
23 changes: 21 additions & 2 deletions Packet++/src/SomeIpSdLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,11 +636,25 @@ bool SomeIpSdLayer::isDataValid(const uint8_t* data, size_t dataLen)
if (!data ||
dataLen < sizeof(someipsdhdr) + sizeof(uint32_t) ||
dataLen < sizeof(someipsdhdr) + sizeof(uint32_t) + getLenEntries(data) + sizeof(uint32_t) ||
dataLen < be32toh(*((uint32_t *)(data + sizeof(someipsdhdr) + sizeof(uint32_t) + getLenEntries(data)))))
dataLen < sizeof(someipsdhdr) + sizeof(uint32_t) + getLenEntries(data) + sizeof(uint32_t) + getLenOptions(data))
{
return false;
}

size_t offsetOption = sizeof(someipsdhdr) + sizeof(uint32_t) + getLenEntries(data) + sizeof(uint32_t);
size_t lenOptions = getLenOptions(data);
uint32_t len = 0;
while (len < lenOptions)
{
if (len + sizeof(uint16_t) + 3 * sizeof(uint8_t) > lenOptions)
return false;

uint32_t lenOption = be16toh(*((uint16_t *)(data + offsetOption + len))) + 3 * sizeof(uint8_t);
len += lenOption;
if (len > lenOptions) // the last must be equal to lenOptions
return false;
}

return true;
}

Expand Down Expand Up @@ -791,7 +805,12 @@ size_t SomeIpSdLayer::getLenEntries(const uint8_t* data)

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

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

void SomeIpSdLayer::setLenEntries(uint32_t length)
Expand Down

0 comments on commit d152bb2

Please sign in to comment.