http_header (trailer) test cleanup

pull/2673/head
Victor Julien 8 years ago
parent 1c46af477e
commit 8d18be1fdb

@ -5430,8 +5430,9 @@ static int DetectEngineHttpHeaderTest33(void)
"\r\n"; "\r\n";
uint32_t http1_len = sizeof(http1_buf) - 1; uint32_t http1_len = sizeof(http1_buf) - 1;
uint32_t http2_len = sizeof(http2_buf) - 1; uint32_t http2_len = sizeof(http2_buf) - 1;
int result = 0;
AppLayerParserThreadCtx *alp_tctx = AppLayerParserThreadCtxAlloc(); AppLayerParserThreadCtx *alp_tctx = AppLayerParserThreadCtxAlloc();
FAIL_IF_NULL(alp_tctx);
memset(&th_v, 0, sizeof(th_v)); memset(&th_v, 0, sizeof(th_v));
memset(&f, 0, sizeof(f)); memset(&f, 0, sizeof(f));
@ -5458,82 +5459,46 @@ static int DetectEngineHttpHeaderTest33(void)
StreamTcpInitConfig(TRUE); StreamTcpInitConfig(TRUE);
de_ctx = DetectEngineCtxInit(); de_ctx = DetectEngineCtxInit();
if (de_ctx == NULL) FAIL_IF(de_ctx == NULL);
goto end;
de_ctx->flags |= DE_QUIET; de_ctx->flags |= DE_QUIET;
de_ctx->sig_list = SigInit(de_ctx,"alert http any any -> any any " de_ctx->sig_list = SigInit(de_ctx,"alert http any any -> any any "
"(content:\"Dummy\"; http_header; " "(content:\"Dummy\"; http_header; "
"sid:1;)"); "sid:1;)");
if (de_ctx->sig_list == NULL) FAIL_IF(de_ctx->sig_list == NULL);
goto end;
SigGroupBuild(de_ctx); SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx); DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
FLOWLOCK_WRLOCK(&f);
int r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP, int r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP,
STREAM_TOSERVER, http1_buf, http1_len); STREAM_TOSERVER, http1_buf, http1_len);
if (r != 0) { FAIL_IF_NOT(r == 0);
printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
result = 0;
FLOWLOCK_UNLOCK(&f);
goto end;
}
FLOWLOCK_UNLOCK(&f);
http_state = f.alstate; http_state = f.alstate;
if (http_state == NULL) { FAIL_IF(http_state == NULL);
printf("no http state: \n");
result = 0;
goto end;
}
/* do detect */ /* do detect */
SigMatchSignatures(&th_v, de_ctx, det_ctx, p1); SigMatchSignatures(&th_v, de_ctx, det_ctx, p1);
if (PacketAlertCheck(p1, 1)) { FAIL_IF(PacketAlertCheck(p1, 1));
printf("sid 1 matched but shouldn't have\n");
goto end;
}
FLOWLOCK_WRLOCK(&f);
r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP, r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP,
STREAM_TOSERVER, http2_buf, http2_len); STREAM_TOSERVER, http2_buf, http2_len);
if (r != 0) { FAIL_IF_NOT(r == 0);
printf("toserver chunk 1 returned %" PRId32 ", expected 0: \n", r);
result = 0;
FLOWLOCK_UNLOCK(&f);
goto end;
}
FLOWLOCK_UNLOCK(&f);
/* do detect */ /* do detect */
SigMatchSignatures(&th_v, de_ctx, det_ctx, p2); SigMatchSignatures(&th_v, de_ctx, det_ctx, p2);
if (!PacketAlertCheck(p2, 1)) { FAIL_IF(!PacketAlertCheck(p2, 1));
printf("sid 1 didn't match but should have\n");
goto end;
}
result = 1;
end: AppLayerParserThreadCtxFree(alp_tctx);
if (alp_tctx != NULL) DetectEngineCtxFree(de_ctx);
AppLayerParserThreadCtxFree(alp_tctx);
if (de_ctx != NULL)
SigGroupCleanup(de_ctx);
if (de_ctx != NULL)
SigCleanSignatures(de_ctx);
if (de_ctx != NULL)
DetectEngineCtxFree(de_ctx);
StreamTcpFreeConfig(TRUE); StreamTcpFreeConfig(TRUE);
FLOW_DESTROY(&f); FLOW_DESTROY(&f);
UTHFreePackets(&p1, 1); UTHFreePackets(&p1, 1);
UTHFreePackets(&p2, 1); UTHFreePackets(&p2, 1);
return result; PASS;
} }
#endif /* UNITTESTS */ #endif /* UNITTESTS */

Loading…
Cancel
Save