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 Heap-buffer-overflow (read) in NflogTlv::getType #1163

Merged
merged 2 commits into from
Aug 2, 2023
Merged
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
7 changes: 5 additions & 2 deletions Packet++/header/TLVData.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,14 @@ namespace pcpp
*/
TLVRecordType getFirstTLVRecord(uint8_t* tlvDataBasePtr, size_t tlvDataLen) const
{
// In most cases tlvDataLen is not zero and the size is correct therefore the overhead is not significant if the checks will be done later
TLVRecordType resRec(tlvDataBasePtr); // for NRVO optimization

// resRec pointer is out-bounds of the TLV records memory
if (resRec.getRecordBasePtr() + resRec.getTotalSize() > tlvDataBasePtr + tlvDataLen)
resRec.assign(NULL);

// check if there are records at all and the total size is not zero
if (tlvDataLen == 0 || resRec.getTotalSize() == 0)
if (!resRec.isNull() && (tlvDataLen == 0 || resRec.getTotalSize() == 0))
resRec.assign(NULL);

return resRec;
Expand Down