]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
dnp3: adds unit test against previous bug
authorPhilippe Antoine <contact@catenacyber.fr>
Tue, 23 Jun 2020 07:08:22 +0000 (09:08 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 7 Jul 2020 08:41:02 +0000 (10:41 +0200)
src/app-layer-dnp3.c

index 7c8653ea89588ede5deb5d7a72f3d36ade35388f..c83e858849006b1433149f227e3bd559d5cae76a 100644 (file)
@@ -2648,6 +2648,37 @@ static int DNP3ParserUnknownEventAlertTest(void)
     PASS;
 }
 
+/**
+* \brief Test that an alert is raised on incorrect data.
+*/
+static int DNP3ParserIncorrectUserData(void)
+{
+    uint8_t packet_bytes[] = {
+        0x05, 0x64, 0x08, 0xc4, 0x03, 0x00, 0x04, 0x00,
+        0xbf, 0xe9, 0xc1, 0xc1, 0x82, 0xc5, 0xee
+    };
+
+    AppLayerParserThreadCtx *alp_tctx = AppLayerParserThreadCtxAlloc();
+    Flow flow;
+    TcpSession ssn;
+    memset(&flow, 0, sizeof(flow));
+    memset(&ssn, 0, sizeof(ssn));
+    flow.protoctx = (void *)&ssn;
+    flow.proto = IPPROTO_TCP;
+    flow.alproto = ALPROTO_DNP3;
+    StreamTcpInitConfig(TRUE);
+
+    int r = AppLayerParserParse(NULL, alp_tctx, &flow, ALPROTO_DNP3,
+                                STREAM_TOCLIENT, packet_bytes, sizeof(packet_bytes));
+
+    FAIL_IF(r == 0);
+
+    AppLayerParserThreadCtxFree(alp_tctx);
+    StreamTcpFreeConfig(TRUE);
+    FLOW_DESTROY(&flow);
+    PASS;
+}
+
 #endif
 
 void DNP3ParserRegisterTests(void)
@@ -2674,5 +2705,6 @@ void DNP3ParserRegisterTests(void)
     UtRegisterTest("DNP3ParserDecodeG70V3Test", DNP3ParserDecodeG70V3Test);
     UtRegisterTest("DNP3ParserUnknownEventAlertTest",
         DNP3ParserUnknownEventAlertTest);
+    UtRegisterTest("DNP3ParserIncorrectUserData", DNP3ParserIncorrectUserData);
 #endif
 }