htp: simplify depth check

pull/4204/head
Victor Julien 6 years ago
parent 972be0a560
commit c68fbfcfe6

@ -501,15 +501,18 @@ static void AppLayerHtpSetStreamDepthFlag(void *tx, uint8_t flags)
} }
} }
static bool AppLayerHtpCheckStreamDepth(uint64_t content_len_so_far, uint8_t flags) static bool AppLayerHtpCheckDepth(const HTPCfgDir *cfg, HtpBody *body, uint8_t flags)
{ {
if (flags & HTP_STREAM_DEPTH_SET) { if (flags & HTP_STREAM_DEPTH_SET) {
uint32_t stream_depth = FileReassemblyDepth(); uint32_t stream_depth = FileReassemblyDepth();
if (content_len_so_far < (uint64_t)stream_depth || stream_depth == 0) { if (body->content_len_so_far < (uint64_t)stream_depth || stream_depth == 0) {
return true;
}
} else {
if (cfg->body_limit == 0 || body->content_len_so_far < cfg->body_limit) {
return true; return true;
} }
} }
return false; return false;
} }
@ -1823,10 +1826,7 @@ static int HTPCallbackRequestBodyData(htp_tx_data_t *d)
SCLogDebug("hstate->cfg->request.body_limit %u", hstate->cfg->request.body_limit); SCLogDebug("hstate->cfg->request.body_limit %u", hstate->cfg->request.body_limit);
/* within limits, add the body chunk to the state. */ /* within limits, add the body chunk to the state. */
if ((!(tx_ud->tsflags & HTP_STREAM_DEPTH_SET) && if (AppLayerHtpCheckDepth(&hstate->cfg->request, &tx_ud->request_body, tx_ud->tsflags)) {
(hstate->cfg->request.body_limit == 0 || tx_ud->request_body.content_len_so_far < hstate->cfg->request.body_limit)) ||
AppLayerHtpCheckStreamDepth(tx_ud->request_body.content_len_so_far, tx_ud->tsflags))
{
uint32_t stream_depth = FileReassemblyDepth(); uint32_t stream_depth = FileReassemblyDepth();
uint32_t len = AppLayerHtpComputeChunkLength(tx_ud->request_body.content_len_so_far, uint32_t len = AppLayerHtpComputeChunkLength(tx_ud->request_body.content_len_so_far,
hstate->cfg->request.body_limit, hstate->cfg->request.body_limit,
@ -1947,10 +1947,7 @@ static int HTPCallbackResponseBodyData(htp_tx_data_t *d)
SCLogDebug("hstate->cfg->response.body_limit %u", hstate->cfg->response.body_limit); SCLogDebug("hstate->cfg->response.body_limit %u", hstate->cfg->response.body_limit);
/* within limits, add the body chunk to the state. */ /* within limits, add the body chunk to the state. */
if ((!(tx_ud->tcflags & HTP_STREAM_DEPTH_SET) && if (AppLayerHtpCheckDepth(&hstate->cfg->response, &tx_ud->response_body, tx_ud->tcflags)) {
(hstate->cfg->response.body_limit == 0 || tx_ud->response_body.content_len_so_far < hstate->cfg->response.body_limit)) ||
AppLayerHtpCheckStreamDepth(tx_ud->response_body.content_len_so_far, tx_ud->tcflags))
{
uint32_t stream_depth = FileReassemblyDepth(); uint32_t stream_depth = FileReassemblyDepth();
uint32_t len = AppLayerHtpComputeChunkLength(tx_ud->response_body.content_len_so_far, uint32_t len = AppLayerHtpComputeChunkLength(tx_ud->response_body.content_len_so_far,
hstate->cfg->response.body_limit, hstate->cfg->response.body_limit,
@ -7327,6 +7324,9 @@ libhtp:\n\
static int HTPParserTest27(void) static int HTPParserTest27(void)
{ {
HTPCfgDir cfg;
memset(&cfg, 0, sizeof(cfg));
cfg.body_limit = 1500;
FileReassemblyDepthEnable(2000); FileReassemblyDepthEnable(2000);
uint32_t len = 1000; uint32_t len = 1000;
@ -7337,7 +7337,7 @@ static int HTPParserTest27(void)
tx_ud->tsflags |= HTP_STREAM_DEPTH_SET; tx_ud->tsflags |= HTP_STREAM_DEPTH_SET;
tx_ud->request_body.content_len_so_far = 2500; tx_ud->request_body.content_len_so_far = 2500;
FAIL_IF(AppLayerHtpCheckStreamDepth(tx_ud->request_body.content_len_so_far, tx_ud->tsflags)); FAIL_IF(AppLayerHtpCheckDepth(&cfg, &tx_ud->request_body, tx_ud->tsflags));
len = AppLayerHtpComputeChunkLength(tx_ud->request_body.content_len_so_far, len = AppLayerHtpComputeChunkLength(tx_ud->request_body.content_len_so_far,
0, 0,

Loading…
Cancel
Save