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=64190 #1240

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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;
}
sashashura marked this conversation as resolved.
Show resolved Hide resolved

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