detect/mpm: fix id confusion in mpm_ctx sharing

Mixing of dynamic id's and hardcoded config values could possibly
lead to the settings not getting applied properly.
pull/5533/head
Victor Julien 6 years ago
parent 82d7f64630
commit ba2a9be11a

@ -967,9 +967,10 @@ enum {
/* Siggroup mpm context profile */
enum {
ENGINE_SGH_MPM_FACTORY_CONTEXT_FULL,
ENGINE_SGH_MPM_FACTORY_CONTEXT_FULL = 0,
ENGINE_SGH_MPM_FACTORY_CONTEXT_SINGLE,
ENGINE_SGH_MPM_FACTORY_CONTEXT_AUTO
ENGINE_SGH_MPM_FACTORY_CONTEXT_AUTO,
#define ENGINE_SGH_MPM_FACTORY_CONTEXT_START_ID_RANGE (ENGINE_SGH_MPM_FACTORY_CONTEXT_AUTO + 1)
};
typedef struct HttpReassembledBody_ {

@ -67,6 +67,7 @@ int32_t MpmFactoryRegisterMpmCtxProfile(
FatalError(SC_ERR_FATAL, "Error allocating memory");
}
memset(de_ctx->mpm_ctx_factory_container, 0, sizeof(MpmCtxFactoryContainer));
de_ctx->mpm_ctx_factory_container->max_id = ENGINE_SGH_MPM_FACTORY_CONTEXT_START_ID_RANGE;
MpmCtxFactoryItem *item = SCMalloc(sizeof(MpmCtxFactoryItem));
if (unlikely(item == NULL)) {
@ -91,10 +92,7 @@ int32_t MpmFactoryRegisterMpmCtxProfile(
}
memset(item[0].mpm_ctx_tc, 0, sizeof(MpmCtx));
item[0].mpm_ctx_tc->flags |= MPMCTX_FLAGS_GLOBAL;
/* our id starts from 0 always. Helps us with the ctx retrieval from
* the array */
item[0].id = 0;
item[0].id = de_ctx->mpm_ctx_factory_container->max_id++;
/* store the newly created item */
de_ctx->mpm_ctx_factory_container->items = item;
@ -161,7 +159,7 @@ int32_t MpmFactoryRegisterMpmCtxProfile(
memset(new_item[0].mpm_ctx_tc, 0, sizeof(MpmCtx));
new_item[0].mpm_ctx_tc->flags |= MPMCTX_FLAGS_GLOBAL;
new_item[0].id = de_ctx->mpm_ctx_factory_container->no_of_items;
new_item[0].id = de_ctx->mpm_ctx_factory_container->max_id++;
de_ctx->mpm_ctx_factory_container->no_of_items++;
/* the newly created id */
@ -200,13 +198,17 @@ MpmCtx *MpmFactoryGetMpmCtxForProfile(const DetectEngineCtx *de_ctx, int32_t id,
} else if (id < -1) {
SCLogError(SC_ERR_INVALID_ARGUMENTS, "Invalid argument - %d\n", id);
return NULL;
} else if (id >= de_ctx->mpm_ctx_factory_container->no_of_items) {
} else if (id >= de_ctx->mpm_ctx_factory_container->max_id) {
/* this id does not exist */
return NULL;
} else {
return (direction == 0) ?
de_ctx->mpm_ctx_factory_container->items[id].mpm_ctx_ts :
de_ctx->mpm_ctx_factory_container->items[id].mpm_ctx_tc;
for (int i = 0; i < de_ctx->mpm_ctx_factory_container->no_of_items; i++) {
if (id == de_ctx->mpm_ctx_factory_container->items[i].id) {
return (direction == 0) ? de_ctx->mpm_ctx_factory_container->items[i].mpm_ctx_ts
: de_ctx->mpm_ctx_factory_container->items[i].mpm_ctx_tc;
}
}
return NULL;
}
}

@ -123,6 +123,7 @@ typedef struct MpmCtxFactoryItem_ {
typedef struct MpmCtxFactoryContainer_ {
MpmCtxFactoryItem *items;
int32_t no_of_items;
int32_t max_id;
} MpmCtxFactoryContainer;
/** pattern is case insensitive */

Loading…
Cancel
Save