]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Use ENGINE_SET_INVALID_EVENT when the packet is too small for an
authorJason Ish <jason.ish@emulex.com>
Fri, 17 Oct 2014 15:33:07 +0000 (09:33 -0600)
committerJason Ish <jason.ish@emulex.com>
Mon, 20 Oct 2014 21:15:06 +0000 (15:15 -0600)
MPLS header, and when the payload type can not be determined.

src/decode-events.h
src/decode-mpls.c

index d794bf5fa92eeab61ae83605d6f17492bcc821a3..658b997312a6aa31d167da42e6092ab30145dec0 100644 (file)
@@ -229,6 +229,7 @@ enum {
     IPV6_IN_IPV6_WRONG_IP_VER,
 
     /* MPLS decode events. */
+    MPLS_HEADER_TOO_SMALL,
     MPLS_BAD_LABEL_ROUTER_ALERT,
     MPLS_BAD_LABEL_IMPLICIT_NULL,
     MPLS_BAD_LABEL_RESERVED,
index 0b125a11e9b9864087ecd4f17aeea269dfdd34b0..86188502031bc1992a6cf5356c7f5176930d7bb9 100644 (file)
@@ -55,6 +55,7 @@ int DecodeMPLS(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt,
 
     do {
         if (len < MPLS_HEADER_LEN) {
+            ENGINE_SET_INVALID_EVENT(p, MPLS_HEADER_TOO_SMALL);
             return TM_ECODE_FAILED;
         }
         shim = *(uint32_t *)pkt;
@@ -98,8 +99,8 @@ int DecodeMPLS(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt,
             pq);
         break;
     default:
-        event = MPLS_UNKNOWN_PAYLOAD_TYPE;
-        break;
+        ENGINE_SET_INVALID_EVENT(p, MPLS_UNKNOWN_PAYLOAD_TYPE);
+        return TM_ECODE_OK;
     }
 
 end:
@@ -111,6 +112,36 @@ end:
 
 #ifdef UNITTESTS
 
+static int DecodeMPLSTestHeaderTooSmall(void)
+{
+    int ret = 1;
+
+    /* A packet that is too small to have a complete MPLS header. */
+    uint8_t pkt[] = {
+        0x00, 0x00, 0x11
+    };
+
+    Packet *p = SCMalloc(SIZE_OF_PACKET);
+    if (unlikely(p == NULL)) {
+        return 0;
+    }
+    ThreadVars tv;
+    DecodeThreadVars dtv;
+
+    memset(&dtv, 0, sizeof(DecodeThreadVars));
+    memset(&tv,  0, sizeof(ThreadVars));
+    memset(p, 0, SIZE_OF_PACKET);
+
+    DecodeMPLS(&tv, &dtv, p, pkt, sizeof(pkt), NULL);
+
+    if (!ENGINE_ISSET_EVENT(p, MPLS_HEADER_TOO_SMALL)) {
+        ret = 0;
+    }
+
+    SCFree(p);
+    return ret;
+}
+
 static int DecodeMPLSTestBadLabelRouterAlert(void)
 {
     int ret = 1;
@@ -280,6 +311,8 @@ static int DecodeMPLSTestUnknownPayloadType(void)
 void DecodeMPLSRegisterTests(void)
 {
 #ifdef UNITTESTS
+    UtRegisterTest("DecodeMPLSTestHeaderTooSmall",
+        DecodeMPLSTestHeaderTooSmall, 1);
     UtRegisterTest("DecodeMPLSTestBadLabelRouterAlert",
         DecodeMPLSTestBadLabelRouterAlert, 1);
     UtRegisterTest("DecodeMPLSTestBadLabelImplicitNull",