From: Anoop Saldanha Date: Tue, 24 Sep 2013 07:53:36 +0000 (+0530) Subject: Unittest to display bug #970(ac-gfbs). X-Git-Tag: suricata-2.0beta2~340 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=92a8b2b738796ffd660d21abfe86f7c0c428e579;p=thirdparty%2Fsuricata.git Unittest to display bug #970(ac-gfbs). --- diff --git a/src/util-mpm-ac-gfbs.c b/src/util-mpm-ac-gfbs.c index 0f66f2b6f0..6a3d3bdc80 100644 --- a/src/util-mpm-ac-gfbs.c +++ b/src/util-mpm-ac-gfbs.c @@ -43,12 +43,15 @@ #include "suricata.h" #include "detect.h" +#include "detect-parse.h" +#include "detect-engine.h" #include "util-mpm-ac-gfbs.h" #include "conf.h" #include "util-memcmp.h" #include "util-debug.h" #include "util-unittest.h" +#include "util-unittest-helper.h" void SCACGfbsInitCtx(MpmCtx *); void SCACGfbsInitThreadCtx(MpmCtx *, MpmThreadCtx *, uint32_t); @@ -2624,6 +2627,61 @@ static int SCACGfbsTest28(void) return result; } +static int SCACGfbsTest29(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_GFBS; + + 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 SCACGfbsRegisterTests(void) @@ -2658,6 +2716,7 @@ void SCACGfbsRegisterTests(void) UtRegisterTest("SCACGfbsTest26", SCACGfbsTest26, 1); UtRegisterTest("SCACGfbsTest27", SCACGfbsTest27, 1); UtRegisterTest("SCACGfbsTest28", SCACGfbsTest28, 1); + UtRegisterTest("SCACGfbsTest29", SCACGfbsTest29, 1); #endif return;