From 60f9f9187d63e45a3603e7470d3c949058688c6e Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 11 Nov 2023 12:15:54 +0000 Subject: [PATCH 1/9] Fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=61820 --- Packet++/header/DhcpLayer.h | 23 ++++++++++++++++++ Packet++/header/IPv4Layer.h | 40 ++++++++++++++++++++++++++++---- Packet++/header/IPv6Extensions.h | 24 +++++++++++++++++++ Packet++/header/NflogLayer.h | 11 +++++++++ Packet++/header/TLVData.h | 25 ++++++++++++++++---- Packet++/header/TcpLayer.h | 24 +++++++++++++++++++ Packet++/src/NflogLayer.cpp | 2 +- 7 files changed, 139 insertions(+), 10 deletions(-) diff --git a/Packet++/header/DhcpLayer.h b/Packet++/header/DhcpLayer.h index 331ef58ca5..b236669407 100644 --- a/Packet++/header/DhcpLayer.h +++ b/Packet++/header/DhcpLayer.h @@ -469,6 +469,29 @@ namespace pcpp memcpy(m_Data->recordValue + valueOffset, stringValue.data(), len); } + /** + * Assign a pointer to the TLV record raw data (byte array) + * @param[in] recordRawData A pointer to the TLV record raw data + * @param[in] tlvDataLen The size of the TLV record raw data + * @return True if data is valid and can be assigned + */ + static bool canAssign(const uint8_t* recordRawData, size_t tlvDataLen) + { + auto data = (TLVRawData*)recordRawData; + if (data == nullptr) + return false; + + if (tlvDataLen < sizeof(TLVRawData::recordType)) + return false; + + if (data->recordType == (uint8_t)DHCPOPT_END || data->recordType == (uint8_t)DHCPOPT_PAD) + return true; + + if (tlvDataLen < sizeof(TLVRawData::recordType) + sizeof(TLVRawData::recordLen)) + return false; + + return true; + } // implement abstract methods diff --git a/Packet++/header/IPv4Layer.h b/Packet++/header/IPv4Layer.h index 52762e3807..d6f2d662fb 100644 --- a/Packet++/header/IPv4Layer.h +++ b/Packet++/header/IPv4Layer.h @@ -313,12 +313,32 @@ namespace pcpp */ IPv4OptionTypes getIPv4OptionType() const { - if (m_Data == nullptr) - return IPV4OPT_Unknown; - - return (IPv4OptionTypes)m_Data->recordType; + return getIPv4OptionType(m_Data); } + /** + * Assign a pointer to the TLV record raw data (byte array) + * @param[in] recordRawData A pointer to the TLV record raw data + * @param[in] tlvDataLen The size of the TLV record raw data + * @return True if data is valid and can be assigned + */ + static bool canAssign(const uint8_t* recordRawData, size_t tlvDataLen) + { + auto data = (TLVRawData*)recordRawData; + if (data == nullptr) + return false; + + if (tlvDataLen < sizeof(TLVRawData::recordType)) + return false; + + if (getIPv4OptionType(data) == (uint8_t)IPV4OPT_EndOfOptionsList || data->recordType == (uint8_t)IPV4OPT_NOP) + return true; + + if (tlvDataLen < sizeof(TLVRawData::recordType) + sizeof(TLVRawData::recordLen)) + return false; + + return true; + } // implement abstract methods @@ -343,6 +363,18 @@ namespace pcpp return (size_t)m_Data->recordLen - (2*sizeof(uint8_t)); } + + private: + /** + * @return IPv4 option type casted as pcpp::IPv4OptionTypes enum + */ + static IPv4OptionTypes getIPv4OptionType(const TLVRawData* data) + { + if (data == nullptr) + return IPV4OPT_Unknown; + + return (IPv4OptionTypes)data->recordType; + } }; diff --git a/Packet++/header/IPv6Extensions.h b/Packet++/header/IPv6Extensions.h index a9df47c345..6ce5609065 100644 --- a/Packet++/header/IPv6Extensions.h +++ b/Packet++/header/IPv6Extensions.h @@ -212,6 +212,30 @@ namespace pcpp */ ~IPv6Option() { } + /** + * Assign a pointer to the TLV record raw data (byte array) + * @param[in] recordRawData A pointer to the TLV record raw data + * @param[in] tlvDataLen The size of the TLV record raw data + * @return True if data is valid and can be assigned + */ + static bool canAssign(const uint8_t* recordRawData, size_t tlvDataLen) + { + auto data = (TLVRawData*)recordRawData; + if (data == nullptr) + return false; + + if (tlvDataLen < sizeof(TLVRawData::recordType)) + return false; + + if (data->recordType == Pad0OptionType) + return true; + + if (tlvDataLen < sizeof(TLVRawData::recordType) + sizeof(TLVRawData::recordLen)) + return false; + + return true; + } + // implement abstract methods size_t getTotalSize() const diff --git a/Packet++/header/NflogLayer.h b/Packet++/header/NflogLayer.h index 5df6358fa3..59c30eff64 100644 --- a/Packet++/header/NflogLayer.h +++ b/Packet++/header/NflogLayer.h @@ -117,6 +117,17 @@ namespace pcpp m_Data = (NflogTLVRawData*)recordRawData; } + /** + * Assign a pointer to the TLV record raw data (byte array) + * @param[in] recordRawData A pointer to the TLV record raw data + * @param[in] tlvDataLen The size of the TLV record raw data + * * @return True if data is valid and can be assigned + */ + static bool canAssign(const uint8_t* recordRawData, size_t tlvDataLen) + { + return recordRawData != nullptr && tlvDataLen >= sizeof(NflogTLVRawData::recordLen); + } + /** * @return True if the TLV record raw data is nullptr, false otherwise */ diff --git a/Packet++/header/TLVData.h b/Packet++/header/TLVData.h index f1731e4388..514a58c381 100644 --- a/Packet++/header/TLVData.h +++ b/Packet++/header/TLVData.h @@ -70,10 +70,18 @@ namespace pcpp */ void assign(uint8_t* recordRawData) { - if(recordRawData == NULL) - m_Data = NULL; - else - m_Data = (TLVRawData*)recordRawData; + m_Data = (TLVRawData*)recordRawData; + } + + /** + * Assign a pointer to the TLV record raw data (byte array) + * @param[in] recordRawData A pointer to the TLV record raw data + * @param[in] tlvDataLen The size of the TLV record raw data + * @return True if data is valid and can be assigned + */ + static bool canAssign(const uint8_t* recordRawData, size_t tlvDataLen) + { + return recordRawData != nullptr && tlvDataLen >= (sizeof(TLVRawData::recordType) + sizeof(TLVRawData::recordLen)); } /** @@ -259,8 +267,11 @@ namespace pcpp */ TLVRecordType getFirstTLVRecord(uint8_t* tlvDataBasePtr, size_t tlvDataLen) const { - TLVRecordType resRec(tlvDataBasePtr); // for NRVO optimization + TLVRecordType resRec(NULL); // for NRVO optimization + if (!TLVRecordType::canAssign(tlvDataBasePtr, tlvDataLen)) + return resRec; + resRec.assign(tlvDataBasePtr); // resRec pointer is out-bounds of the TLV records memory if (resRec.getRecordBasePtr() + resRec.getTotalSize() > tlvDataBasePtr + tlvDataLen) resRec.assign(NULL); @@ -288,7 +299,11 @@ namespace pcpp if (record.isNull()) return resRec; + if (!TLVRecordType::canAssign(record.getRecordBasePtr() + record.getTotalSize(), tlvDataBasePtr - record.getRecordBasePtr() + tlvDataLen - record.getTotalSize())) + return resRec; + resRec.assign(record.getRecordBasePtr() + record.getTotalSize()); + if (resRec.getTotalSize() == 0) resRec.assign(NULL); diff --git a/Packet++/header/TcpLayer.h b/Packet++/header/TcpLayer.h index 21e792679f..457e2b3e30 100644 --- a/Packet++/header/TcpLayer.h +++ b/Packet++/header/TcpLayer.h @@ -222,6 +222,30 @@ namespace pcpp return (TcpOptionType)m_Data->recordType; } + /** + * Assign a pointer to the TLV record raw data (byte array) + * @param[in] recordRawData A pointer to the TLV record raw data + * @param[in] tlvDataLen The size of the TLV record raw data + * @return True if data is valid and can be assigned + */ + static bool canAssign(const uint8_t* recordRawData, size_t tlvDataLen) + { + auto data = (TLVRawData*)recordRawData; + if (data == nullptr) + return false; + + if (tlvDataLen < sizeof(TLVRawData::recordType)) + return false; + + if (data->recordType == (uint8_t)PCPP_TCPOPT_NOP || data->recordType == (uint8_t)PCPP_TCPOPT_EOL) + return true; + + if (tlvDataLen < sizeof(TLVRawData::recordType) + sizeof(TLVRawData::recordLen)) + return false; + + return true; + } + // implement abstract methods size_t getTotalSize() const diff --git a/Packet++/src/NflogLayer.cpp b/Packet++/src/NflogLayer.cpp index bd3fe5d8ed..c7a067bd86 100644 --- a/Packet++/src/NflogLayer.cpp +++ b/Packet++/src/NflogLayer.cpp @@ -88,7 +88,7 @@ size_t NflogLayer::getHeaderLen() const headerLen += currentTLV.getTotalSize(); currentTLV = m_TlvReader.getNextTLVRecord(currentTLV, getTlvsBasePtr(), m_DataLen - sizeof(nflog_header)); } - if (currentTLV.getType() == static_cast (NflogTlvType::NFULA_PAYLOAD)) + if (!currentTLV.isNull() && currentTLV.getType() == static_cast (NflogTlvType::NFULA_PAYLOAD)) { // for the length and type of the payload TLV headerLen += 2 * sizeof (uint16_t); From fa2fab51cacd1581af2ff7a34a7dbce09a8e07ae Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 11 Nov 2023 12:51:22 +0000 Subject: [PATCH 2/9] Disable deprecation warnings --- CMakeLists.txt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d2251c622c..7cc1e589c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -182,6 +182,13 @@ else() endif() endif() +if(PCAPPP_TARGET_COMPILER_CLANG + OR PCAPPP_TARGET_COMPILER_GCC + OR PCAPPP_TARGET_COMPILER_INTEL) + # Disable deprecated warnings since warnings are treated as errors + add_definitions("-Wno-deprecated-declarations") +endif() + if(PCAPPP_USE_DPDK) find_package(DPDK) if(NOT DPDK_FOUND) @@ -197,8 +204,6 @@ if(PCAPPP_USE_DPDK) add_definitions(-DUSE_DPDK_KNI) endif() - # Disable deprecated warnings when DPDK enabled since warnings are treated as errors - add_definitions("-Wno-deprecated-declarations") configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/setup_dpdk.py" "${CMAKE_CURRENT_BINARY_DIR}" COPYONLY) endif() @@ -243,8 +248,8 @@ endif() if(PCAPPP_TARGET_COMPILER_MSVC) # Disable VS warnings: Unknown pragma (4068), Zero-sized array in struct/union (4200), Possible loss of data (4244), - # Possible loss of data (4267), Character may not be represented (4819) - add_definitions("/wd4068 /wd4200 /wd4244 /wd4267 /wd4819") + # Possible loss of data (4267), Character may not be represented (4819), Deprecated (4996) + add_definitions("/wd4068 /wd4200 /wd4244 /wd4267 /wd4819 /wd4996") endif() if(PCAPPP_BUILD_COVERAGE) From 089704f2ba71a0ab35ca6dd68334e806de7ee3e3 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 11 Nov 2023 13:21:33 +0000 Subject: [PATCH 3/9] Fix possible use after free warning --- Packet++/header/TLVData.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Packet++/header/TLVData.h b/Packet++/header/TLVData.h index 514a58c381..9c2ddd6bf9 100644 --- a/Packet++/header/TLVData.h +++ b/Packet++/header/TLVData.h @@ -163,7 +163,14 @@ namespace pcpp /** * Free the memory of the TLV record raw data */ - void purgeRecordData() { if (!isNull()) delete [] m_Data; } + void purgeRecordData() + { + if (!isNull()) + { + delete [] m_Data; + m_Data = nullptr; + } + } /** * A templated method to retrieve the record data as a certain type T. For example, if record data is 4B long From 22b16d70f0520b3e7599c3e4593a6718508a496c Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 12 Nov 2023 09:17:07 +0000 Subject: [PATCH 4/9] Suppress false positive warning --- Packet++/src/IPv6Extensions.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Packet++/src/IPv6Extensions.cpp b/Packet++/src/IPv6Extensions.cpp index 2ce69ab704..ae2d4384ad 100644 --- a/Packet++/src/IPv6Extensions.cpp +++ b/Packet++/src/IPv6Extensions.cpp @@ -110,7 +110,14 @@ IPv6TLVOptionHeader::IPv6Option IPv6TLVOptionHeader::IPv6TLVOptionBuilder::build if (m_RecType != IPv6TLVOptionHeader::IPv6Option::Pad0OptionType) { recordBuffer[0] = recType; +#if defined(__GNUC__) && __GNUC__ >= 10 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstringop-overflow" +#endif recordBuffer[1] = static_cast(m_RecValueLen); +#if defined(__GNUC__) && __GNUC__ >= 10 + #pragma GCC diagnostic pop +#endif if (m_RecValueLen > 0) memcpy(recordBuffer+2, m_RecValue, m_RecValueLen); } From 004d0ade4654d122cfeb35694c5b81ee8a18e64d Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 21 Nov 2023 14:53:56 +0000 Subject: [PATCH 5/9] Revert "Disable deprecation warnings" This reverts commit fa2fab51cacd1581af2ff7a34a7dbce09a8e07ae. --- CMakeLists.txt | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7cc1e589c0..d2251c622c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -182,13 +182,6 @@ else() endif() endif() -if(PCAPPP_TARGET_COMPILER_CLANG - OR PCAPPP_TARGET_COMPILER_GCC - OR PCAPPP_TARGET_COMPILER_INTEL) - # Disable deprecated warnings since warnings are treated as errors - add_definitions("-Wno-deprecated-declarations") -endif() - if(PCAPPP_USE_DPDK) find_package(DPDK) if(NOT DPDK_FOUND) @@ -204,6 +197,8 @@ if(PCAPPP_USE_DPDK) add_definitions(-DUSE_DPDK_KNI) endif() + # Disable deprecated warnings when DPDK enabled since warnings are treated as errors + add_definitions("-Wno-deprecated-declarations") configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/setup_dpdk.py" "${CMAKE_CURRENT_BINARY_DIR}" COPYONLY) endif() @@ -248,8 +243,8 @@ endif() if(PCAPPP_TARGET_COMPILER_MSVC) # Disable VS warnings: Unknown pragma (4068), Zero-sized array in struct/union (4200), Possible loss of data (4244), - # Possible loss of data (4267), Character may not be represented (4819), Deprecated (4996) - add_definitions("/wd4068 /wd4200 /wd4244 /wd4267 /wd4819 /wd4996") + # Possible loss of data (4267), Character may not be represented (4819) + add_definitions("/wd4068 /wd4200 /wd4244 /wd4267 /wd4819") endif() if(PCAPPP_BUILD_COVERAGE) From 8da8983d8768431d9e15f5b4506706c3dcf7b341 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 21 Nov 2023 14:59:44 +0000 Subject: [PATCH 6/9] Revert "Suppress false positive warning" This reverts commit 22b16d70f0520b3e7599c3e4593a6718508a496c. --- Packet++/src/IPv6Extensions.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Packet++/src/IPv6Extensions.cpp b/Packet++/src/IPv6Extensions.cpp index ae2d4384ad..2ce69ab704 100644 --- a/Packet++/src/IPv6Extensions.cpp +++ b/Packet++/src/IPv6Extensions.cpp @@ -110,14 +110,7 @@ IPv6TLVOptionHeader::IPv6Option IPv6TLVOptionHeader::IPv6TLVOptionBuilder::build if (m_RecType != IPv6TLVOptionHeader::IPv6Option::Pad0OptionType) { recordBuffer[0] = recType; -#if defined(__GNUC__) && __GNUC__ >= 10 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wstringop-overflow" -#endif recordBuffer[1] = static_cast(m_RecValueLen); -#if defined(__GNUC__) && __GNUC__ >= 10 - #pragma GCC diagnostic pop -#endif if (m_RecValueLen > 0) memcpy(recordBuffer+2, m_RecValue, m_RecValueLen); } From 03a4f77fdf73d009f25141498d9bd37057161324 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 21 Nov 2023 15:05:32 +0000 Subject: [PATCH 7/9] Fix comment --- Packet++/header/DhcpLayer.h | 2 +- Packet++/header/IPv4Layer.h | 2 +- Packet++/header/IPv6Extensions.h | 2 +- Packet++/header/NflogLayer.h | 2 +- Packet++/header/TLVData.h | 2 +- Packet++/header/TcpLayer.h | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Packet++/header/DhcpLayer.h b/Packet++/header/DhcpLayer.h index b236669407..8906728c3d 100644 --- a/Packet++/header/DhcpLayer.h +++ b/Packet++/header/DhcpLayer.h @@ -470,7 +470,7 @@ namespace pcpp } /** - * Assign a pointer to the TLV record raw data (byte array) + * Check if a pointer can be assigned to the TLV record data * @param[in] recordRawData A pointer to the TLV record raw data * @param[in] tlvDataLen The size of the TLV record raw data * @return True if data is valid and can be assigned diff --git a/Packet++/header/IPv4Layer.h b/Packet++/header/IPv4Layer.h index d6f2d662fb..34fd33dec9 100644 --- a/Packet++/header/IPv4Layer.h +++ b/Packet++/header/IPv4Layer.h @@ -317,7 +317,7 @@ namespace pcpp } /** - * Assign a pointer to the TLV record raw data (byte array) + * Check if a pointer can be assigned to the TLV record data * @param[in] recordRawData A pointer to the TLV record raw data * @param[in] tlvDataLen The size of the TLV record raw data * @return True if data is valid and can be assigned diff --git a/Packet++/header/IPv6Extensions.h b/Packet++/header/IPv6Extensions.h index 6ce5609065..40f3819273 100644 --- a/Packet++/header/IPv6Extensions.h +++ b/Packet++/header/IPv6Extensions.h @@ -213,7 +213,7 @@ namespace pcpp ~IPv6Option() { } /** - * Assign a pointer to the TLV record raw data (byte array) + * Check if a pointer can be assigned to the TLV record data * @param[in] recordRawData A pointer to the TLV record raw data * @param[in] tlvDataLen The size of the TLV record raw data * @return True if data is valid and can be assigned diff --git a/Packet++/header/NflogLayer.h b/Packet++/header/NflogLayer.h index 59c30eff64..c93d3064d1 100644 --- a/Packet++/header/NflogLayer.h +++ b/Packet++/header/NflogLayer.h @@ -118,7 +118,7 @@ namespace pcpp } /** - * Assign a pointer to the TLV record raw data (byte array) + * Check if a pointer can be assigned to the TLV record data * @param[in] recordRawData A pointer to the TLV record raw data * @param[in] tlvDataLen The size of the TLV record raw data * * @return True if data is valid and can be assigned diff --git a/Packet++/header/TLVData.h b/Packet++/header/TLVData.h index 9c2ddd6bf9..84072931ca 100644 --- a/Packet++/header/TLVData.h +++ b/Packet++/header/TLVData.h @@ -74,7 +74,7 @@ namespace pcpp } /** - * Assign a pointer to the TLV record raw data (byte array) + * Check if a pointer can be assigned to the TLV record data * @param[in] recordRawData A pointer to the TLV record raw data * @param[in] tlvDataLen The size of the TLV record raw data * @return True if data is valid and can be assigned diff --git a/Packet++/header/TcpLayer.h b/Packet++/header/TcpLayer.h index 457e2b3e30..6dfccc8ca5 100644 --- a/Packet++/header/TcpLayer.h +++ b/Packet++/header/TcpLayer.h @@ -223,7 +223,7 @@ namespace pcpp } /** - * Assign a pointer to the TLV record raw data (byte array) + * Check if a pointer can be assigned to the TLV record data * @param[in] recordRawData A pointer to the TLV record raw data * @param[in] tlvDataLen The size of the TLV record raw data * @return True if data is valid and can be assigned From 3625934dabf46dc42e9547a5857c80e2f9136247 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 21 Nov 2023 15:11:54 +0000 Subject: [PATCH 8/9] Invert if --- Packet++/header/DhcpLayer.h | 5 +---- Packet++/header/IPv4Layer.h | 5 +---- Packet++/header/IPv6Extensions.h | 5 +---- Packet++/header/TcpLayer.h | 5 +---- 4 files changed, 4 insertions(+), 16 deletions(-) diff --git a/Packet++/header/DhcpLayer.h b/Packet++/header/DhcpLayer.h index 8906728c3d..2107d06f29 100644 --- a/Packet++/header/DhcpLayer.h +++ b/Packet++/header/DhcpLayer.h @@ -487,10 +487,7 @@ namespace pcpp if (data->recordType == (uint8_t)DHCPOPT_END || data->recordType == (uint8_t)DHCPOPT_PAD) return true; - if (tlvDataLen < sizeof(TLVRawData::recordType) + sizeof(TLVRawData::recordLen)) - return false; - - return true; + return tlvDataLen >= sizeof(TLVRawData::recordType) + sizeof(TLVRawData::recordLen); } // implement abstract methods diff --git a/Packet++/header/IPv4Layer.h b/Packet++/header/IPv4Layer.h index 34fd33dec9..cb23f3f421 100644 --- a/Packet++/header/IPv4Layer.h +++ b/Packet++/header/IPv4Layer.h @@ -334,10 +334,7 @@ namespace pcpp if (getIPv4OptionType(data) == (uint8_t)IPV4OPT_EndOfOptionsList || data->recordType == (uint8_t)IPV4OPT_NOP) return true; - if (tlvDataLen < sizeof(TLVRawData::recordType) + sizeof(TLVRawData::recordLen)) - return false; - - return true; + return tlvDataLen >= sizeof(TLVRawData::recordType) + sizeof(TLVRawData::recordLen); } // implement abstract methods diff --git a/Packet++/header/IPv6Extensions.h b/Packet++/header/IPv6Extensions.h index 40f3819273..74ba1baeee 100644 --- a/Packet++/header/IPv6Extensions.h +++ b/Packet++/header/IPv6Extensions.h @@ -230,10 +230,7 @@ namespace pcpp if (data->recordType == Pad0OptionType) return true; - if (tlvDataLen < sizeof(TLVRawData::recordType) + sizeof(TLVRawData::recordLen)) - return false; - - return true; + return tlvDataLen >= sizeof(TLVRawData::recordType) + sizeof(TLVRawData::recordLen); } // implement abstract methods diff --git a/Packet++/header/TcpLayer.h b/Packet++/header/TcpLayer.h index 6dfccc8ca5..08aece03b2 100644 --- a/Packet++/header/TcpLayer.h +++ b/Packet++/header/TcpLayer.h @@ -240,10 +240,7 @@ namespace pcpp if (data->recordType == (uint8_t)PCPP_TCPOPT_NOP || data->recordType == (uint8_t)PCPP_TCPOPT_EOL) return true; - if (tlvDataLen < sizeof(TLVRawData::recordType) + sizeof(TLVRawData::recordLen)) - return false; - - return true; + return tlvDataLen >= sizeof(TLVRawData::recordType) + sizeof(TLVRawData::recordLen); } // implement abstract methods From 35c740e4ff23d14e2eab2cee5d6f3fa3f4f20cad Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 21 Nov 2023 15:24:39 +0000 Subject: [PATCH 9/9] Call base method --- Packet++/header/DhcpLayer.h | 2 +- Packet++/header/IPv4Layer.h | 2 +- Packet++/header/IPv6Extensions.h | 2 +- Packet++/header/TcpLayer.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Packet++/header/DhcpLayer.h b/Packet++/header/DhcpLayer.h index 2107d06f29..82d9791294 100644 --- a/Packet++/header/DhcpLayer.h +++ b/Packet++/header/DhcpLayer.h @@ -487,7 +487,7 @@ namespace pcpp if (data->recordType == (uint8_t)DHCPOPT_END || data->recordType == (uint8_t)DHCPOPT_PAD) return true; - return tlvDataLen >= sizeof(TLVRawData::recordType) + sizeof(TLVRawData::recordLen); + return TLVRecord::canAssign(recordRawData, tlvDataLen); } // implement abstract methods diff --git a/Packet++/header/IPv4Layer.h b/Packet++/header/IPv4Layer.h index cb23f3f421..ee959d1b92 100644 --- a/Packet++/header/IPv4Layer.h +++ b/Packet++/header/IPv4Layer.h @@ -334,7 +334,7 @@ namespace pcpp if (getIPv4OptionType(data) == (uint8_t)IPV4OPT_EndOfOptionsList || data->recordType == (uint8_t)IPV4OPT_NOP) return true; - return tlvDataLen >= sizeof(TLVRawData::recordType) + sizeof(TLVRawData::recordLen); + return TLVRecord::canAssign(recordRawData, tlvDataLen); } // implement abstract methods diff --git a/Packet++/header/IPv6Extensions.h b/Packet++/header/IPv6Extensions.h index 74ba1baeee..6e48695c37 100644 --- a/Packet++/header/IPv6Extensions.h +++ b/Packet++/header/IPv6Extensions.h @@ -230,7 +230,7 @@ namespace pcpp if (data->recordType == Pad0OptionType) return true; - return tlvDataLen >= sizeof(TLVRawData::recordType) + sizeof(TLVRawData::recordLen); + return TLVRecord::canAssign(recordRawData, tlvDataLen); } // implement abstract methods diff --git a/Packet++/header/TcpLayer.h b/Packet++/header/TcpLayer.h index 08aece03b2..50b89ca9bc 100644 --- a/Packet++/header/TcpLayer.h +++ b/Packet++/header/TcpLayer.h @@ -240,7 +240,7 @@ namespace pcpp if (data->recordType == (uint8_t)PCPP_TCPOPT_NOP || data->recordType == (uint8_t)PCPP_TCPOPT_EOL) return true; - return tlvDataLen >= sizeof(TLVRawData::recordType) + sizeof(TLVRawData::recordLen); + return TLVRecord::canAssign(recordRawData, tlvDataLen); } // implement abstract methods