]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Unittest to display bug #970(ac-bs).
authorAnoop Saldanha <anoopsaldanha@gmail.com>
Tue, 24 Sep 2013 07:43:11 +0000 (13:13 +0530)
committerVictor Julien <victor@inliniac.net>
Tue, 24 Sep 2013 13:20:25 +0000 (15:20 +0200)
src/util-mpm-ac-bs.c

index 84fbc23f61d0fcd4b103350bf6ae8fdf704d7769..0d36a93793a668a092a58b2025329fe9976438f7 100644 (file)
 #include "suricata.h"
 
 #include "detect.h"
+#include "detect-parse.h"
+#include "detect-engine.h"
 #include "util-mpm-ac-bs.h"
 
 #include "conf.h"
 #include "util-debug.h"
 #include "util-unittest.h"
+#include "util-unittest-helper.h"
 #include "util-memcmp.h"
 
 void SCACBSInitCtx(MpmCtx *);
@@ -2703,6 +2706,61 @@ static int SCACBSTest29(void)
     return result;
 }
 
+static int SCACBSTest30(void)
+{
+    uint8_t *buf = (uint8_t *)"onetwothreefourfivesixseveneightnine";
+    uint16_t buflen = strlen((char *)buf);
+    Packet *p = NULL;
+    ThreadVars th_v;
+    DetectEngineThreadCtx *det_ctx = NULL;
+    int result = 0;
+
+    memset(&th_v, 0, sizeof(th_v));
+    p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
+
+    DetectEngineCtx *de_ctx = DetectEngineCtxInit();
+    if (de_ctx == NULL)
+        goto end;
+    de_ctx->mpm_matcher = MPM_AC_BS;
+
+    de_ctx->flags |= DE_QUIET;
+
+    de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
+                               "(content:\"onetwothreefourfivesixseveneightnine\"; sid:1;)");
+    if (de_ctx->sig_list == NULL)
+        goto end;
+    de_ctx->sig_list->next = SigInit(de_ctx, "alert tcp any any -> any any "
+                               "(content:\"onetwothreefourfivesixseveneightnine\"; fast_pattern:3,3; sid:2;)");
+    if (de_ctx->sig_list->next == NULL)
+        goto end;
+
+    SigGroupBuild(de_ctx);
+    DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
+
+    SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
+    if (PacketAlertCheck(p, 1) != 1) {
+        printf("if (PacketAlertCheck(p, 1) != 1) failure\n");
+        goto end;
+    }
+    if (PacketAlertCheck(p, 2) != 1) {
+        printf("if (PacketAlertCheck(p, 1) != 2) failure\n");
+        goto end;
+    }
+
+    result = 1;
+end:
+    if (de_ctx != NULL) {
+        SigGroupCleanup(de_ctx);
+        SigCleanSignatures(de_ctx);
+
+        DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
+        DetectEngineCtxFree(de_ctx);
+    }
+
+    UTHFreePackets(&p, 1);
+    return result;
+}
+
 #endif /* UNITTESTS */
 
 void SCACBSRegisterTests(void)
@@ -2738,6 +2796,7 @@ void SCACBSRegisterTests(void)
     UtRegisterTest("SCACBSTest27", SCACBSTest27, 1);
     UtRegisterTest("SCACBSTest28", SCACBSTest28, 1);
     UtRegisterTest("SCACBSTest29", SCACBSTest29, 1);
+    UtRegisterTest("SCACBSTest30", SCACBSTest30, 1);
 #endif
 
     return;