In DetectAppLayerInspectEngineCopyListToDetectCtx
Avoid quadratic complexity by remembering last element
of the linked list we are inserting into
void DetectMpmInitializeAppMpms(DetectEngineCtx *de_ctx)
{
const DetectBufferMpmRegistery *list = g_mpm_list[DETECT_BUFFER_MPM_TYPE_APP];
+ DetectBufferMpmRegistery *toadd = de_ctx->app_mpms_list;
while (list != NULL) {
DetectBufferMpmRegistery *n = SCCalloc(1, sizeof(*n));
BUG_ON(n == NULL);
*n = *list;
n->next = NULL;
- if (de_ctx->app_mpms_list == NULL) {
+ if (toadd == NULL) {
+ toadd = n;
de_ctx->app_mpms_list = n;
} else {
- DetectBufferMpmRegistery *t = de_ctx->app_mpms_list;
- while (t->next != NULL) {
- t = t->next;
- }
- t->next = n;
+ toadd->next = n;
+ toadd = toadd->next;
}
/* default to whatever the global setting is */
static void DetectAppLayerInspectEngineCopyListToDetectCtx(DetectEngineCtx *de_ctx)
{
const DetectEngineAppInspectionEngine *t = g_app_inspect_engines;
+ DetectEngineAppInspectionEngine *list = de_ctx->app_inspect_engines;
while (t) {
DetectEngineAppInspectionEngine *new_engine = SCCalloc(1, sizeof(DetectEngineAppInspectionEngine));
if (unlikely(new_engine == NULL)) {
new_engine->progress = t->progress;
new_engine->v2 = t->v2;
- if (de_ctx->app_inspect_engines == NULL) {
+ if (list == NULL) {
de_ctx->app_inspect_engines = new_engine;
} else {
- DetectEngineAppInspectionEngine *list = de_ctx->app_inspect_engines;
- while (list->next != NULL) {
- list = list->next;
- }
-
list->next = new_engine;
}
+ list = new_engine;
t = t->next;
}