From 127bcedb1d066d2df86fdac89e6aada8d61a1e0a Mon Sep 17 00:00:00 2001 From: aled-ua Date: Tue, 24 Dec 2024 07:57:19 +0000 Subject: [PATCH 1/4] Fix vuln OSV-2024-382 --- Packet++/src/UdpLayer.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Packet++/src/UdpLayer.cpp b/Packet++/src/UdpLayer.cpp index 9cfaa2cbe0..5158793dab 100644 --- a/Packet++/src/UdpLayer.cpp +++ b/Packet++/src/UdpLayer.cpp @@ -37,11 +37,19 @@ namespace pcpp uint16_t UdpLayer::getSrcPort() const { + if (m_DataLen < sizeof(udphdr)) { + PCPP_LOG_ERROR("Buffer too small to access source port"); + return 0; // Return an invalid port number + } return be16toh(getUdpHeader()->portSrc); } uint16_t UdpLayer::getDstPort() const { + if (m_DataLen < sizeof(udphdr)) { + PCPP_LOG_ERROR("Buffer too small to access destination port"); + return 0; // Return an invalid port number + } return be16toh(getUdpHeader()->portDst); } @@ -151,6 +159,10 @@ namespace pcpp void UdpLayer::computeCalculateFields() { udphdr* udpHdr = (udphdr*)m_Data; + if (m_DataLen < sizeof(udphdr)) { + PCPP_LOG_ERROR("Buffer too small to calculate fields"); + return; + } udpHdr->length = htobe16(m_DataLen); calculateChecksum(true); } From 1493433b82d6530bf6ce81391a504fa10a6b1583 Mon Sep 17 00:00:00 2001 From: aled-ua Date: Fri, 10 Jan 2025 15:36:01 +0800 Subject: [PATCH 2/4] Fix format err --- Packet++/src/UdpLayer.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Packet++/src/UdpLayer.cpp b/Packet++/src/UdpLayer.cpp index 5158793dab..7ee1e4818a 100644 --- a/Packet++/src/UdpLayer.cpp +++ b/Packet++/src/UdpLayer.cpp @@ -37,7 +37,8 @@ namespace pcpp uint16_t UdpLayer::getSrcPort() const { - if (m_DataLen < sizeof(udphdr)) { + if (m_DataLen < sizeof(udphdr)) + { PCPP_LOG_ERROR("Buffer too small to access source port"); return 0; // Return an invalid port number } @@ -46,7 +47,8 @@ namespace pcpp uint16_t UdpLayer::getDstPort() const { - if (m_DataLen < sizeof(udphdr)) { + if (m_DataLen < sizeof(udphdr)) + { PCPP_LOG_ERROR("Buffer too small to access destination port"); return 0; // Return an invalid port number } @@ -159,7 +161,8 @@ namespace pcpp void UdpLayer::computeCalculateFields() { udphdr* udpHdr = (udphdr*)m_Data; - if (m_DataLen < sizeof(udphdr)) { + if (m_DataLen < sizeof(udphdr)) + { PCPP_LOG_ERROR("Buffer too small to calculate fields"); return; } From ac92d06aafc6a1b1c721b6228bedf33e2da51806 Mon Sep 17 00:00:00 2001 From: aled-ua Date: Fri, 10 Jan 2025 16:12:19 +0800 Subject: [PATCH 3/4] Fix format err --- Packet++/src/UdpLayer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Packet++/src/UdpLayer.cpp b/Packet++/src/UdpLayer.cpp index 7ee1e4818a..d14f3fcfdc 100644 --- a/Packet++/src/UdpLayer.cpp +++ b/Packet++/src/UdpLayer.cpp @@ -40,7 +40,7 @@ namespace pcpp if (m_DataLen < sizeof(udphdr)) { PCPP_LOG_ERROR("Buffer too small to access source port"); - return 0; // Return an invalid port number + return 0; // Return an invalid port number } return be16toh(getUdpHeader()->portSrc); } @@ -50,7 +50,7 @@ namespace pcpp if (m_DataLen < sizeof(udphdr)) { PCPP_LOG_ERROR("Buffer too small to access destination port"); - return 0; // Return an invalid port number + return 0; // Return an invalid port number } return be16toh(getUdpHeader()->portDst); } From 0ebbb2390aac36094bc36dd23b6d15c63c46aeae Mon Sep 17 00:00:00 2001 From: aled-ua Date: Fri, 31 Jan 2025 11:23:40 +0800 Subject: [PATCH 4/4] Check at the start of the function --- Packet++/src/UdpLayer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packet++/src/UdpLayer.cpp b/Packet++/src/UdpLayer.cpp index d14f3fcfdc..dec9cb9b4e 100644 --- a/Packet++/src/UdpLayer.cpp +++ b/Packet++/src/UdpLayer.cpp @@ -160,12 +160,12 @@ namespace pcpp void UdpLayer::computeCalculateFields() { - udphdr* udpHdr = (udphdr*)m_Data; if (m_DataLen < sizeof(udphdr)) { PCPP_LOG_ERROR("Buffer too small to calculate fields"); return; } + udphdr* udpHdr = (udphdr*)m_Data; udpHdr->length = htobe16(m_DataLen); calculateChecksum(true); }