unittests: clean up memory for htp body test

pull/14025/head
Victor Julien 1 month ago committed by Victor Julien
parent 52aa922735
commit 43347e3d3d

@ -4735,19 +4735,19 @@ libhtp:\n\
/** \test BG box crash -- chunks are messed up. Observed for real. */
static int HTPBodyReassemblyTest01(void)
{
HtpTxUserData htud;
memset(&htud, 0x00, sizeof(htud));
HtpTxUserData *htud = HTPCalloc(1, sizeof(*htud));
FAIL_IF_NULL(htud);
HtpState hstate;
memset(&hstate, 0x00, sizeof(hstate));
Flow flow;
memset(&flow, 0x00, sizeof(flow));
AppLayerParserState *parser = AppLayerParserStateAlloc();
htp_cfg_t *cfg = htp_config_create();
BUG_ON(cfg == NULL);
FAIL_IF(cfg == NULL);
htp_connp_t *connp = htp_connp_create(cfg);
BUG_ON(connp == NULL);
FAIL_IF(connp == NULL);
const htp_tx_t *tx = htp_connp_get_request_tx(connp);
BUG_ON(tx == NULL);
FAIL_IF(tx == NULL);
hstate.f = &flow;
flow.alparser = parser;
@ -4755,15 +4755,15 @@ static int HTPBodyReassemblyTest01(void)
uint8_t chunk1[] = "--e5a320f21416a02493a0a6f561b1c494\r\nContent-Disposition: form-data; name=\"uploadfile\"; filename=\"D2GUef.jpg\"\r";
uint8_t chunk2[] = "POST /uri HTTP/1.1\r\nHost: hostname.com\r\nKeep-Alive: 115\r\nAccept-Charset: utf-8\r\nUser-Agent: Mozilla/5.0 (X11; Linux i686; rv:9.0.1) Gecko/20100101 Firefox/9.0.1\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nConnection: keep-alive\r\nContent-length: 68102\r\nReferer: http://otherhost.com\r\nAccept-Encoding: gzip\r\nContent-Type: multipart/form-data; boundary=e5a320f21416a02493a0a6f561b1c494\r\nCookie: blah\r\nAccept-Language: us\r\n\r\n--e5a320f21416a02493a0a6f561b1c494\r\nContent-Disposition: form-data; name=\"uploadfile\"; filename=\"D2GUef.jpg\"\r";
int r = HtpBodyAppendChunk(&htud.request_body, chunk1, sizeof(chunk1) - 1);
BUG_ON(r != 0);
r = HtpBodyAppendChunk(&htud.request_body, chunk2, sizeof(chunk2) - 1);
BUG_ON(r != 0);
int r = HtpBodyAppendChunk(&htud->request_body, chunk1, sizeof(chunk1) - 1);
FAIL_IF(r != 0);
r = HtpBodyAppendChunk(&htud->request_body, chunk2, sizeof(chunk2) - 1);
FAIL_IF(r != 0);
const uint8_t *chunks_buffer = NULL;
uint32_t chunks_buffer_len = 0;
HtpRequestBodyReassemble(&htud, &chunks_buffer, &chunks_buffer_len);
HtpRequestBodyReassemble(htud, &chunks_buffer, &chunks_buffer_len);
FAIL_IF_NULL(chunks_buffer);
#ifdef PRINT
printf("REASSCHUNK START: \n");
@ -4771,16 +4771,20 @@ static int HTPBodyReassemblyTest01(void)
printf("REASSCHUNK END: \n");
#endif
htud.mime_state = SCMimeStateInit((const uint8_t *)"multipart/form-data; boundary=toto",
htud->mime_state = SCMimeStateInit((const uint8_t *)"multipart/form-data; boundary=toto",
strlen("multipart/form-data; boundary=toto"));
FAIL_IF_NULL(htud.mime_state);
htud.tsflags |= HTP_BOUNDARY_SET;
HtpRequestBodyHandleMultipart(&hstate, &htud, &tx, chunks_buffer, chunks_buffer_len, false);
FAIL_IF_NULL(htud->mime_state);
htud->tsflags |= HTP_BOUNDARY_SET;
HtpRequestBodyHandleMultipart(&hstate, htud, &tx, chunks_buffer, chunks_buffer_len, false);
FAIL_IF(htud.request_body.content_len_so_far != 669);
FAIL_IF(htud->request_body.content_len_so_far != 669);
FAIL_IF_NOT_NULL(htud.files_ts.head);
FAIL_IF_NOT_NULL(htud->files_ts.head);
htp_connp_destroy_all(connp);
HtpTxUserDataFree(htud);
AppLayerParserStateFree(parser);
htp_config_destroy(cfg);
PASS;
}

Loading…
Cancel
Save