]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
decode/udp: fix payload_len calculation
authorShivani Bhardwaj <shivani@oisf.net>
Wed, 4 Jan 2023 06:30:13 +0000 (12:00 +0530)
committerVictor Julien <vjulien@oisf.net>
Thu, 26 Jan 2023 05:59:14 +0000 (06:59 +0100)
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

src/decode-udp.c

index 13c665cdd8504b4f171fdc58c6becd25a01009d8..1ecaf54f6f1abf63f83a98b52550fefc3ae55761 100644 (file)
@@ -56,11 +56,16 @@ static int DecodeUDPPacket(ThreadVars *t, Packet *p, const uint8_t *pkt, uint16_
         return -1;
     }
 
+    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;