From: Shivani Bhardwaj Date: Wed, 4 Jan 2023 06:30:13 +0000 (+0530) Subject: decode/udp: fix payload_len calculation X-Git-Tag: suricata-6.0.10~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb26d1a64d99b1320768c42f86ed7314a625c52a;p=thirdparty%2Fsuricata.git decode/udp: fix payload_len calculation Fix payload_len calculation post removal of the condition that returned error code if the length to the decode fn did not match the length of header from the UDP packet. Bug 5379 (cherry picked from commit f941ceae2be883596a3571ec9046ea884d3f3f85) --- diff --git a/src/decode-udp.c b/src/decode-udp.c index 2464364e64..7fe10af40c 100644 --- a/src/decode-udp.c +++ b/src/decode-udp.c @@ -60,12 +60,16 @@ static int DecodeUDPPacket(ThreadVars *t, Packet *p, const uint8_t *pkt, uint16_ // packet can still be valid, keeping for consistency with decoder.udp.hlen_invalid event ENGINE_SET_INVALID_EVENT(p, UDP_HLEN_INVALID); } + if (unlikely(UDP_GET_LEN(p) < UDP_HEADER_LEN)) { + ENGINE_SET_INVALID_EVENT(p, UDP_LEN_INVALID); + return -1; + } SET_UDP_SRC_PORT(p,&p->sp); SET_UDP_DST_PORT(p,&p->dp); p->payload = (uint8_t *)pkt + UDP_HEADER_LEN; - p->payload_len = len - UDP_HEADER_LEN; + p->payload_len = UDP_GET_LEN(p) - UDP_HEADER_LEN; p->proto = IPPROTO_UDP;