Skip to content

Commit

Permalink
Fix Heap-buffer-overflow (read) in NflogTlv::getType (seladb#1163)
Browse files Browse the repository at this point in the history
  • Loading branch information
sashashura authored and fxlb committed Oct 22, 2024
1 parent 2875568 commit 36a4e2c
Showing 1 changed file with 5 additions and 2 deletions.
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

0 comments on commit 36a4e2c

Please sign in to comment.