File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments