Skip to content

Commit 127bced

Browse files
committed
Fix vuln OSV-2024-382
1 parent f81ced2 commit 127bced

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Packet++/src/UdpLayer.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,19 @@ namespace pcpp
3737

3838
uint16_t UdpLayer::getSrcPort() const
3939
{
40+
if (m_DataLen < sizeof(udphdr)) {
41+
PCPP_LOG_ERROR("Buffer too small to access source port");
42+
return 0; // Return an invalid port number
43+
}
4044
return be16toh(getUdpHeader()->portSrc);
4145
}
4246

4347
uint16_t UdpLayer::getDstPort() const
4448
{
49+
if (m_DataLen < sizeof(udphdr)) {
50+
PCPP_LOG_ERROR("Buffer too small to access destination port");
51+
return 0; // Return an invalid port number
52+
}
4553
return be16toh(getUdpHeader()->portDst);
4654
}
4755

@@ -151,6 +159,10 @@ namespace pcpp
151159
void UdpLayer::computeCalculateFields()
152160
{
153161
udphdr* udpHdr = (udphdr*)m_Data;
162+
if (m_DataLen < sizeof(udphdr)) {
163+
PCPP_LOG_ERROR("Buffer too small to calculate fields");
164+
return;
165+
}
154166
udpHdr->length = htobe16(m_DataLen);
155167
calculateChecksum(true);
156168
}

0 commit comments

Comments
 (0)