ThreadVars th_v;
DetectEngineThreadCtx *det_ctx = NULL;
DetectEngineCtx *de_ctx = NULL;
- int result = 0;
memset(&th_v, 0, sizeof(th_v));
memset(p, 0, SIZE_OF_PACKET);
HostBitsTestSetup();
de_ctx = DetectEngineCtxInit();
-
- if (de_ctx == NULL) {
- printf("bad de_ctx: ");
- goto end;
- }
+ FAIL_IF_NULL(de_ctx);
de_ctx->flags |= DE_QUIET;
s = de_ctx->sig_list = SigInit(de_ctx,"alert ip any any -> any any (hostbits:set,abc; content:\"GET \"; sid:1;)");
-
- if (s == NULL) {
- printf("bad sig: ");
- goto end;
- }
+ FAIL_IF_NULL(s);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
- result = 1;
-
-end:
if (de_ctx != NULL) {
SigGroupCleanup(de_ctx);
SigCleanSignatures(de_ctx);
HostBitsTestShutdown();
SCFree(p);
- return result;
+ PASS;
}
/**
Signature *s = NULL;
ThreadVars th_v;
DetectEngineCtx *de_ctx = NULL;
- int result = 0;
- int error_count = 0;
memset(&th_v, 0, sizeof(th_v));
de_ctx = DetectEngineCtxInit();
- if (de_ctx == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(de_ctx);
de_ctx->flags |= DE_QUIET;
s = DetectEngineAppendSig(de_ctx,
"alert ip any any -> any any (hostbits:isset,abc,src; content:\"GET \"; sid:1;)");
- if (s == NULL) {
- error_count++;
- }
+ FAIL_IF_NULL(s);
s = DetectEngineAppendSig(de_ctx,
"alert ip any any -> any any (hostbits:isnotset,abc,dst; content:\"GET \"; sid:2;)");
- if (s == NULL) {
- error_count++;
- }
+ FAIL_IF_NULL(s);
+
/* TODO reenable after both is supported
s = DetectEngineAppendSig(de_ctx,
"alert ip any any -> any any (hostbits:set,abc,both; content:\"GET \"; sid:3;)");
- if (s == NULL) {
- error_count++;
- }
+ FAIL_IF_NULL(s);
*/
s = DetectEngineAppendSig(de_ctx,
"alert ip any any -> any any (hostbits:unset,abc,src; content:\"GET \"; sid:4;)");
- if (s == NULL) {
- error_count++;
- }
+ FAIL_IF_NULL(s);
s = DetectEngineAppendSig(de_ctx,
"alert ip any any -> any any (hostbits:toggle,abc,dst; content:\"GET \"; sid:5;)");
- if (s == NULL) {
- error_count++;
- }
-
- if (error_count != 0)
- goto end;
-
- result = 1;
+ FAIL_IF_NULL(s);
SigGroupCleanup(de_ctx);
SigCleanSignatures(de_ctx);
DetectEngineCtxFree(de_ctx);
- return result;
-end:
- if (de_ctx != NULL) {
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
- DetectEngineCtxFree(de_ctx);
- }
-
- return result;
+ PASS;
}
#if 0
ThreadVars th_v;
DetectEngineThreadCtx *det_ctx = NULL;
DetectEngineCtx *de_ctx = NULL;
- int result = 0;
int idx = 0;
memset(&th_v, 0, sizeof(th_v));
HostBitsTestSetup();
de_ctx = DetectEngineCtxInit();
-
- if (de_ctx == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(de_ctx);
de_ctx->flags |= DE_QUIET;
s = de_ctx->sig_list = SigInit(de_ctx,"alert ip any any -> any any (msg:\"isset option\"; hostbits:isset,fbt; content:\"GET \"; sid:1;)");
+ FAIL_IF_NULL(s);
idx = VariableNameGetIdx(de_ctx, "fbt", VAR_TYPE_HOST_BIT);
-
- if (s == NULL || idx != 1) {
- goto end;
- }
+ FAIL_IF(idx != 1);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
- result = 1;
-
SigGroupCleanup(de_ctx);
SigCleanSignatures(de_ctx);
HostBitsTestShutdown();
SCFree(p);
- return result;
-
-end:
-
- if (de_ctx != NULL) {
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
- }
-
- if (det_ctx != NULL) {
- DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
- }
-
- if (de_ctx != NULL) {
- DetectEngineCtxFree(de_ctx);
- }
-
- HostBitsTestShutdown();
-
- SCFree(p);
- return result;
+ PASS;
}
/**
ThreadVars th_v;
DetectEngineThreadCtx *det_ctx = NULL;
DetectEngineCtx *de_ctx = NULL;
- int result = 0;
memset(&th_v, 0, sizeof(th_v));
memset(p, 0, SIZE_OF_PACKET);
HostBitsTestSetup();
de_ctx = DetectEngineCtxInit();
-
- if (de_ctx == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(de_ctx);
de_ctx->flags |= DE_QUIET;
s = de_ctx->sig_list = SigInit(de_ctx,
"alert ip any any -> any any (hostbits:noalert; content:\"GET \"; sid:1;)");
-
- if (s == NULL || ((s->flags & SIG_FLAG_NOALERT) != SIG_FLAG_NOALERT)) {
- goto end;
- }
+ FAIL_IF_NULL(s);
+ FAIL_IF((s->flags & SIG_FLAG_NOALERT) != SIG_FLAG_NOALERT);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
- if (!PacketAlertCheck(p, 1)) {
- result = 1;
- }
+ FAIL_IF(PacketAlertCheck(p, 1));
SigGroupCleanup(de_ctx);
SigCleanSignatures(de_ctx);
HostBitsTestShutdown();
SCFree(p);
- return result;
-end:
-
- if (de_ctx != NULL) {
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
- }
-
- if (det_ctx != NULL) {
- DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
- }
-
- if (de_ctx != NULL) {
- DetectEngineCtxFree(de_ctx);
- }
-
- HostBitsTestShutdown();
-
- SCFree(p);
- return result;
+ PASS;
}
#if 0
FLOW_DESTROY(&f);
SCFree(p);
- return result;
-}
+ return result;}
#endif
/**
p->proto = IPPROTO_TCP;
de_ctx = DetectEngineCtxInit();
-
- if (de_ctx == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(de_ctx);
de_ctx->flags |= DE_QUIET;
s = de_ctx->sig_list = SigInit(de_ctx,
"alert ip any any -> any any (hostbits:set,myflow2; sid:10;)");
-
- if (s == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(s);
s = s->next = SigInit(de_ctx,
"alert ip any any -> any any (hostbits:isset,myflow2; sid:11;)");
-
- if (s == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(s);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
result = 1;
}
}
+ FAIL_IF_NOT(result);
SigGroupCleanup(de_ctx);
SigCleanSignatures(de_ctx);
HostBitsTestShutdown();
SCFree(p);
- return result;
-end:
-
- if (de_ctx != NULL) {
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
- }
-
- if (det_ctx != NULL) {
- DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
- }
-
- if (de_ctx != NULL) {
- DetectEngineCtxFree(de_ctx);
- }
-
- FLOW_DESTROY(&f);
-
- HostBitsTestShutdown();
- SCFree(p);
- return result;
+ PASS;
}
/**
DetectEngineThreadCtx *det_ctx = NULL;
DetectEngineCtx *de_ctx = NULL;
Flow f;
- int result = 0;
memset(p, 0, SIZE_OF_PACKET);
memset(&th_v, 0, sizeof(th_v));
p->proto = IPPROTO_TCP;
de_ctx = DetectEngineCtxInit();
-
- if (de_ctx == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(de_ctx);
de_ctx->flags |= DE_QUIET;
s = DetectEngineAppendSig(de_ctx,
"alert ip any any -> any any (hostbits:set,myflow2; sid:10;)");
- if (s == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(s);
s = DetectEngineAppendSig(de_ctx,
"alert ip any any -> any any (hostbits:toggle,myflow2; sid:11;)");
- if (s == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(s);
s = DetectEngineAppendSig(de_ctx,
"alert ip any any -> any any (hostbits:toggle,myflow2; sid:12;)");
- if (s == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(s);
s = DetectEngineAppendSig(de_ctx,
"alert ip any any -> any any (hostbits:isset,myflow2; sid:13;)");
- if (s == NULL) {
- goto end;
- }
+ FAIL_IF_NULL(s);
SCSigRegisterSignatureOrderingFuncs(de_ctx);
SCSigOrderSignatures(de_ctx);
}
if (PacketAlertCheck(p, 13)) {
SCLogInfo("sid 13 matched");
- result = 1;
+ } else {
+ FAIL;
}
}
HostBitsTestShutdown();
SCFree(p);
- return result;
-end:
-
- if (de_ctx != NULL) {
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
- }
-
- if (det_ctx != NULL) {
- DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
- }
-
- if (de_ctx != NULL) {
- DetectEngineCtxFree(de_ctx);
- }
-
- FLOW_DESTROY(&f);
-
- HostBitsTestShutdown();
-
- SCFree(p);
- return result;
+ PASS;
}
#endif /* UNITTESTS */