Skip to content

Commit

Permalink
Fix Heap-buffer-overflow (read) in NflogTlv::getType
Browse files Browse the repository at this point in the history
  • Loading branch information
sashashura committed Jul 21, 2023
1 parent 5cdf3b7 commit 006e259
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 006e259

Please sign in to comment.