detect: guard rate filter callback registration, return bool on failure - #15553
Closed
kenifor wants to merge 2 commits into
Closed
detect: guard rate filter callback registration, return bool on failure#15553kenifor wants to merge 2 commits into
kenifor wants to merge 2 commits into
Conversation
added 2 commits
June 4, 2026 13:29
SCDetectEngineRegisterRateFilterCallback() calls DetectEngineGetCurrent() and dereferences the result unconditionally. DetectEngineGetCurrent() can return NULL when no suitable engine is registered as current — for example when a plugin calls this API before the detect engine is initialized. Add a NULL guard and return false so callers can detect registration failure. Flagged by Svace and confirmed by gcc -fanalyzer. Ticket: 8560
…abled Wrap SCDetectEngineRegisterRateFilterCallback() in both bundled library examples with a DetectEngineEnabled() check so it is only called when detection is active. Log a warning if detection is disabled so the omission is visible to developers.
catenacyber
reviewed
Jun 4, 2026
| de_ctx->RateFilterCallback = fn; | ||
| de_ctx->rate_filter_callback_arg = arg; | ||
| DetectEngineDeReference(&de_ctx); | ||
| return true; |
Contributor
There was a problem hiding this comment.
Why do we add a return value and ignore it ?
Contributor
There was a problem hiding this comment.
Looks like #15380 (comment) was not taken into account
Author
There was a problem hiding this comment.
Looks like #15380 (comment) was not taken into account
Addressed in #15558: reverted the return type back to void — adding bool while ignoring the return value in all call sites was pointless. The NULL guard and SCLogError are kept; examples are unchanged.
Contributor
There was a problem hiding this comment.
I think it is right to have a bool return value, but the examples should use it and warn as commented in #15380 (comment)
5 tasks
5 tasks
Contributor
|
Replaced by #15558 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SCDetectEngineRegisterRateFilterCallback()callsDetectEngineGetCurrent()and dereferences the result unconditionally.DetectEngineGetCurrent()can return NULL when a plugin calls this API before the detect engine is initialized — the bundled library examples do exactly this.Fixes:
SCLogErrorandreturn falseso callers can detect registration failurevoid→boolexamples/lib/custom/main.c,examples/lib/live/main.c) to checkDetectEngineEnabled()first and log aSCLogWarningwhen detection is disabledFlagged by Svace static analyzer and confirmed by
gcc -fanalyzer(see #15380).This supersedes #15380 (new PR per contribution workflow, rebased on current main, all reviewer feedback addressed).
Ticket: 8560