detect/entropy: Ensure entropy matcher has flow

Make sure that the flow is available to the entropy matcher so it can
handle content that's not anchored to a sticky buffer.

Issue: 7838
pull/13856/head
Jeff Lucovsky 1 year ago committed by Victor Julien
parent e62eb00459
commit 9f32550e18

@ -497,7 +497,7 @@ static int DetectEngineContentInspectionInternal(DetectEngineThreadCtx *det_ctx,
} while (1);
} else if (smd->type == DETECT_ENTROPY) {
if (!DetectEntropyDoMatch(det_ctx, s, smd->ctx, buffer, buffer_len)) {
if (!DetectEntropyDoMatch(det_ctx, s, smd->ctx, f, buffer, buffer_len)) {
goto no_match;
}
goto match;

@ -37,12 +37,15 @@ static int DetectEntropySetup(DetectEngineCtx *de_ctx, Signature *s, const char
int sm_list = DETECT_SM_LIST_PMATCH;
if (s->init_data->list != DETECT_SM_LIST_NOTSET) {
/* sticky buffer */
if (DetectBufferGetActiveList(de_ctx, s) == -1)
goto error;
sm_list = s->init_data->list;
ded->fv_idx = VarNameStoreRegister(
DetectEngineBufferTypeGetNameById(de_ctx, sm_list), VAR_TYPE_FLOW_FLOAT);
} else {
ded->fv_idx = VarNameStoreRegister("content", VAR_TYPE_FLOW_FLOAT);
}
if (SCSigMatchAppendSMToList(de_ctx, s, DETECT_ENTROPY, (SigMatchCtx *)ded, sm_list) != NULL) {
@ -69,14 +72,14 @@ static void DetectEntropyFree(DetectEngineCtx *de_ctx, void *ptr)
}
bool DetectEntropyDoMatch(DetectEngineThreadCtx *det_ctx, const Signature *s,
const SigMatchCtx *ctx, const uint8_t *buffer, const uint32_t buffer_len)
const SigMatchCtx *ctx, Flow *flow, const uint8_t *buffer, const uint32_t buffer_len)
{
double entropy = -1.0;
bool rc = SCDetectEntropyMatch(buffer, buffer_len, (const DetectEntropyData *)ctx, &entropy);
if (entropy != -1.0) {
if (flow && entropy != -1.0) {
DetectEntropyData *ded = (DetectEntropyData *)ctx;
FlowVarAddFloat(det_ctx->p->flow, ded->fv_idx, entropy);
FlowVarAddFloat(flow, ded->fv_idx, entropy);
}
return rc;

@ -20,6 +20,6 @@
void DetectEntropyRegister(void);
bool DetectEntropyDoMatch(DetectEngineThreadCtx *det_ctx, const Signature *s,
const SigMatchCtx *ctx, const uint8_t *buffer, const uint32_t buffer_len);
const SigMatchCtx *ctx, Flow *flow, const uint8_t *buffer, const uint32_t buffer_len);
#endif

Loading…
Cancel
Save