Skip to content

detect: guard rate filter callback registration, return bool on failure - #15553

Closed
kenifor wants to merge 2 commits into
OISF:mainfrom
kenifor:fix-rate-filter-callback
Closed

detect: guard rate filter callback registration, return bool on failure#15553
kenifor wants to merge 2 commits into
OISF:mainfrom
kenifor:fix-rate-filter-callback

Conversation

@kenifor

@kenifor kenifor commented Jun 4, 2026

Copy link
Copy Markdown

Summary

SCDetectEngineRegisterRateFilterCallback() calls DetectEngineGetCurrent() 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:

  • Added NULL guard with SCLogError and return false so callers can detect registration failure
  • Changed return type voidbool
  • Updated both bundled examples (examples/lib/custom/main.c, examples/lib/live/main.c) to check DetectEngineEnabled() first and log a SCLogWarning when detection is disabled

Flagged 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

Denis Balashov 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.
@kenifor
kenifor requested review from a team and victorjulien as code owners June 4, 2026 10:30
Comment thread src/detect-engine.c
de_ctx->RateFilterCallback = fn;
de_ctx->rate_filter_callback_arg = arg;
DetectEngineDeReference(&de_ctx);
return true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we add a return value and ignore it ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like #15380 (comment) was not taken into account

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it is right to have a bool return value, but the examples should use it and warn as commented in #15380 (comment)

@catenacyber

Copy link
Copy Markdown
Contributor

Replaced by #15558

@catenacyber catenacyber closed this Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants