Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gen/refactor: transform and misc related changes for improved transform support #12502

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
detect/engine: Prevent double-free of keyword hash
Issue: 2290

Defer freeing the keyword hash table until the engine context has
been freed. This eliminates a double-free from occurring.

For the unittests ONLY, clear the keyword_hash to prevent a double
free attempt.
jlucovsky committed Jan 29, 2025
commit 1de19ed19662224e157d03d9062af1982803f349
5 changes: 4 additions & 1 deletion src/detect-engine.c
Original file line number Diff line number Diff line change
@@ -2606,6 +2606,9 @@ DetectEngineCtx *DetectEngineCtxInitWithPrefix(const char *prefix, uint32_t tena
static void DetectEngineCtxFreeThreadKeywordData(DetectEngineCtx *de_ctx)
{
HashListTableFree(de_ctx->keyword_hash);
#if UNITTESTS
de_ctx->keyword_hash = NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double free Happens only in unit tests, right ? Just double checking

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And why was CI green if there was this double free ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a unit test only situation.

The double free would occur in DetectUnregsiterThreadCtxFuncs iff keyword hash wasn't nullified.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And why was CI green if there was this double free ?

#endif
}

static void DetectEngineCtxFreeFailedSigs(DetectEngineCtx *de_ctx)
@@ -2678,7 +2681,6 @@ void DetectEngineCtxFree(DetectEngineCtx *de_ctx)

MpmFactoryDeRegisterAllMpmCtxProfiles(de_ctx);

DetectEngineCtxFreeThreadKeywordData(de_ctx);
SRepDestroy(de_ctx);
DetectEngineCtxFreeFailedSigs(de_ctx);

@@ -2701,6 +2703,7 @@ void DetectEngineCtxFree(DetectEngineCtx *de_ctx)
DetectPortCleanupList(de_ctx, de_ctx->udp_priorityports);

DetectBufferTypeFreeDetectEngine(de_ctx);
DetectEngineCtxFreeThreadKeywordData(de_ctx);
SCClassConfDeinit(de_ctx);
SCReferenceConfDeinit(de_ctx);