{
TcpSession ssn;
Flow f;
- Packet *p = NULL;
ThreadVars th_v;
- DetectEngineCtx *de_ctx = NULL;
DetectEngineThreadCtx *det_ctx = NULL;
- int result = 0;
AppLayerParserThreadCtx *alp_tctx = AppLayerParserThreadCtxAlloc();
+ FAIL_IF_NULL(alp_tctx);
+
memset(&th_v, 0, sizeof(th_v));
memset(&f, 0, sizeof(f));
memset(&ssn, 0, sizeof(ssn));
StreamTcpInitConfig(TRUE);
- de_ctx = DetectEngineCtxInit();
- if (de_ctx == NULL)
- goto end;
+ DetectEngineCtx *de_ctx = DetectEngineCtxInit();
+ FAIL_IF_NULL(de_ctx);
+ de_ctx->flags |= DE_QUIET;
FLOW_INITIALIZE(&f);
f.protoctx = (void *)&ssn;
f.alproto = ALPROTO_HTTP;
SCLogDebug("sig %s", sig);
- DetectEngineAppendSig(de_ctx, (char *)sig);
-
- de_ctx->flags |= DE_QUIET;
-
- if (de_ctx->sig_list == NULL)
- goto end;
+ Signature *s = DetectEngineAppendSig(de_ctx, (char *)sig);
+ FAIL_IF_NULL(s);
SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
+ FAIL_IF_NULL(det_ctx);
struct TestSteps *b = steps;
int i = 0;
while (b->input != NULL) {
SCLogDebug("chunk %p %d", b, i);
- p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
- if (p == NULL)
- goto end;
+ Packet *p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
+ FAIL_IF_NULL(p);
p->flow = &f;
p->flowflags = (b->direction == STREAM_TOSERVER) ? FLOW_PKT_TOSERVER : FLOW_PKT_TOCLIENT;
p->flowflags |= FLOW_PKT_ESTABLISHED;
p->flags |= PKT_HAS_FLOW|PKT_STREAM_EST;
- FLOWLOCK_WRLOCK(&f);
int r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP,
b->direction, (uint8_t *)b->input,
b->input_size ? b->input_size : strlen((const char *)b->input));
- if (r != 0) {
- printf("toserver chunk %d returned %" PRId32 ", expected 0: ", i+1, r);
- result = 0;
- FLOWLOCK_UNLOCK(&f);
- goto end;
- }
- FLOWLOCK_UNLOCK(&f);
+ FAIL_IF_NOT(r == 0);
/* do detect */
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
int match = PacketAlertCheck(p, 1);
- if (b->expect != match) {
- printf("rule matching mismatch: ");
- goto end;
- }
+ FAIL_IF_NOT (b->expect == match);
UTHFreePackets(&p, 1);
- p = NULL;
b++;
i++;
}
- result = 1;
- end:
- if (alp_tctx != NULL)
- AppLayerParserThreadCtxFree(alp_tctx);
- if (de_ctx != NULL)
- SigGroupCleanup(de_ctx);
- if (de_ctx != NULL)
- SigCleanSignatures(de_ctx);
- if (de_ctx != NULL)
- DetectEngineCtxFree(de_ctx);
+ DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
+ AppLayerParserThreadCtxFree(alp_tctx);
+ DetectEngineCtxFree(de_ctx);
StreamTcpFreeConfig(TRUE);
FLOW_DESTROY(&f);
- UTHFreePackets(&p, 1);
if (yaml) {
HtpConfigRestoreBackup();
ConfRestoreContextBackup();
}
- return result;
+ PASS;
}
static int DetectEngineHttpClientBodyTest01(void)
static int DetectHttpClientBodySetup(DetectEngineCtx *, Signature *, const char *);
static void DetectHttpClientBodyRegisterTests(void);
-static void DetectHttpClientBodyFree(void *);
static void DetectHttpClientBodySetupCallback(const DetectEngineCtx *de_ctx,
Signature *s);
static int g_http_client_body_buffer_id = 0;
sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].name = "http_client_body";
sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].desc = "content modifier to match only on HTTP request-body";
sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].url = DOC_URL DOC_VERSION "/rules/http-keywords.html#http-client-body";
- sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].Match = NULL;
sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].Setup = DetectHttpClientBodySetup;
- sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].Free = DetectHttpClientBodyFree;
sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].RegisterTests = DetectHttpClientBodyRegisterTests;
-
sigmatch_table[DETECT_AL_HTTP_CLIENT_BODY].flags |= SIGMATCH_NOOPT ;
DetectAppLayerMpmRegister("http_client_body", SIG_FLAG_TOSERVER, 2,
ALPROTO_HTTP);
}
-/**
- * \brief The function to free the http_client_body data.
- *
- * \param ptr Pointer to the http_client_body.
- */
-void DetectHttpClientBodyFree(void *ptr)
-{
- SCEnter();
- DetectContentData *hcbd = (DetectContentData *)ptr;
- if (hcbd == NULL)
- SCReturn;
-
- if (hcbd->content != NULL)
- SCFree(hcbd->content);
-
- SpmDestroyCtx(hcbd->spm_ctx);
- SCFree(hcbd);
-
- SCReturn;
-}
-
/************************************Unittests*********************************/
#ifdef UNITTESTS
}
end:
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
DetectEngineCtxFree(de_ctx);
return result;
result = 1;
end:
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
DetectEngineCtxFree(de_ctx);
return result;
result = 1;
end:
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
DetectEngineCtxFree(de_ctx);
return result;
result = 1;
end:
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
DetectEngineCtxFree(de_ctx);
return result;
result = 1;
end:
- SigGroupCleanup(de_ctx);
- SigCleanSignatures(de_ctx);
DetectEngineCtxFree(de_ctx);
return result;
end:
if (alp_tctx != NULL)
AppLayerParserThreadCtxFree(alp_tctx);
- if (de_ctx != NULL)
- SigGroupCleanup(de_ctx);
- if (de_ctx != NULL)
- SigCleanSignatures(de_ctx);
if (de_ctx != NULL)
DetectEngineCtxFree(de_ctx);
end:
if (alp_tctx != NULL)
AppLayerParserThreadCtxFree(alp_tctx);
- if (de_ctx != NULL)
- SigGroupCleanup(de_ctx);
- if (de_ctx != NULL)
- SigCleanSignatures(de_ctx);
if (de_ctx != NULL)
DetectEngineCtxFree(de_ctx);
end:
if (alp_tctx != NULL)
AppLayerParserThreadCtxFree(alp_tctx);
- if (de_ctx != NULL)
- SigGroupCleanup(de_ctx);
- if (de_ctx != NULL)
- SigCleanSignatures(de_ctx);
if (de_ctx != NULL)
DetectEngineCtxFree(de_ctx);
end:
if (alp_tctx != NULL)
AppLayerParserThreadCtxFree(alp_tctx);
- if (de_ctx != NULL)
- SigGroupCleanup(de_ctx);
- if (de_ctx != NULL)
- SigCleanSignatures(de_ctx);
if (de_ctx != NULL)
DetectEngineCtxFree(de_ctx);
end:
if (alp_tctx != NULL)
AppLayerParserThreadCtxFree(alp_tctx);
- if (de_ctx != NULL)
- SigGroupCleanup(de_ctx);
- if (de_ctx != NULL)
- SigCleanSignatures(de_ctx);
if (de_ctx != NULL)
DetectEngineCtxFree(de_ctx);
end:
if (alp_tctx != NULL)
AppLayerParserThreadCtxFree(alp_tctx);
- if (de_ctx != NULL)
- SigGroupCleanup(de_ctx);
- if (de_ctx != NULL)
- SigCleanSignatures(de_ctx);
if (de_ctx != NULL)
DetectEngineCtxFree(de_ctx);
end:
if (alp_tctx != NULL)
AppLayerParserThreadCtxFree(alp_tctx);
- if (de_ctx != NULL)
- SigGroupCleanup(de_ctx);
- if (de_ctx != NULL)
- SigCleanSignatures(de_ctx);
if (de_ctx != NULL)
DetectEngineCtxFree(de_ctx);
end:
if (alp_tctx != NULL)
AppLayerParserThreadCtxFree(alp_tctx);
- if (de_ctx != NULL)
- SigGroupCleanup(de_ctx);
- if (de_ctx != NULL)
- SigCleanSignatures(de_ctx);
if (de_ctx != NULL)
DetectEngineCtxFree(de_ctx);
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
}
if (de_ctx != NULL) {
- SigGroupCleanup(de_ctx);
DetectEngineCtxFree(de_ctx);
}
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
}
if (de_ctx != NULL) {
- SigGroupCleanup(de_ctx);
DetectEngineCtxFree(de_ctx);
}
return result;
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
static int DetectHttpClientBodyTest22(void)
{
DetectEngineCtx *de_ctx = NULL;
result = 1;
end:
- SigCleanSignatures(de_ctx);
DetectEngineCtxFree(de_ctx);
return result;
}
result = 1;
end:
- SigCleanSignatures(de_ctx);
DetectEngineCtxFree(de_ctx);
return result;
}
result = 1;
end:
- SigCleanSignatures(de_ctx);
DetectEngineCtxFree(de_ctx);
return result;
}
result = 1;
end:
- SigCleanSignatures(de_ctx);
DetectEngineCtxFree(de_ctx);
return result;
}
result = 1;
end:
- SigCleanSignatures(de_ctx);
DetectEngineCtxFree(de_ctx);
return result;
}
result = 1;
end:
- SigCleanSignatures(de_ctx);
DetectEngineCtxFree(de_ctx);
return result;
}
result = 1;
end:
- SigCleanSignatures(de_ctx);
DetectEngineCtxFree(de_ctx);
return result;
}
result = 1;
end:
- SigCleanSignatures(de_ctx);
DetectEngineCtxFree(de_ctx);
return result;
}
result = 1;
end:
- SigCleanSignatures(de_ctx);
DetectEngineCtxFree(de_ctx);
return result;
}
result = 1;
end:
- SigCleanSignatures(de_ctx);
DetectEngineCtxFree(de_ctx);
return result;
}
result = 1;
end:
- SigCleanSignatures(de_ctx);
DetectEngineCtxFree(de_ctx);
return result;
}
result = 1;
end:
- SigCleanSignatures(de_ctx);
DetectEngineCtxFree(de_ctx);
return result;
}
result = 1;
end:
- SigCleanSignatures(de_ctx);
DetectEngineCtxFree(de_ctx);
return result;
}
result = 1;
end:
- SigCleanSignatures(de_ctx);
DetectEngineCtxFree(de_ctx);
return result;
}
result = 1;
end:
- SigCleanSignatures(de_ctx);
DetectEngineCtxFree(de_ctx);
return result;
}