diff --git a/examples/lib/custom/main.c b/examples/lib/custom/main.c index 30e99b05fc10..eaef6e300073 100644 --- a/examples/lib/custom/main.c +++ b/examples/lib/custom/main.c @@ -253,7 +253,9 @@ int main(int argc, char **argv) * ThreadVars will be ready. */ SuricataInit(); - SCDetectEngineRegisterRateFilterCallback(RateFilterCallback, NULL); + if (DetectEngineEnabled()) { + SCDetectEngineRegisterRateFilterCallback(RateFilterCallback, NULL); + } /* Spawn our worker threads. */ pthread_t worker; diff --git a/examples/lib/live/main.c b/examples/lib/live/main.c index ff509f40ef64..1bb3933f21f4 100644 --- a/examples/lib/live/main.c +++ b/examples/lib/live/main.c @@ -306,7 +306,9 @@ int main(int argc, char **argv) * ThreadVars will be ready. */ SuricataInit(); - SCDetectEngineRegisterRateFilterCallback(RateFilterCallback, NULL); + if (DetectEngineEnabled()) { + SCDetectEngineRegisterRateFilterCallback(RateFilterCallback, NULL); + } /* Spawn our worker threads, one for each interface. */ pthread_t workers[MAX_INTERFACES]; diff --git a/src/detect-engine.c b/src/detect-engine.c index 382462641a35..c8d58a64dbf6 100644 --- a/src/detect-engine.c +++ b/src/detect-engine.c @@ -5122,12 +5122,18 @@ void DetectLowerSetupCallback( } } -void SCDetectEngineRegisterRateFilterCallback(SCDetectRateFilterFunc fn, void *arg) +bool SCDetectEngineRegisterRateFilterCallback(SCDetectRateFilterFunc fn, void *arg) { DetectEngineCtx *de_ctx = DetectEngineGetCurrent(); + if (de_ctx == NULL) { + SCLogError("no detection engine available for rate filter callback registration"); + return false; + } + de_ctx->RateFilterCallback = fn; de_ctx->rate_filter_callback_arg = arg; DetectEngineDeReference(&de_ctx); + return true; } int DetectEngineThreadCtxGetJsonContext(DetectEngineThreadCtx *det_ctx) diff --git a/src/detect.h b/src/detect.h index 5c6eab3204b0..5403dee82153 100644 --- a/src/detect.h +++ b/src/detect.h @@ -1175,7 +1175,7 @@ typedef struct DetectEngineCtx_ { * This callback is added to the current detection engine and will be * copied to all future detection engines over rule reloads. */ -void SCDetectEngineRegisterRateFilterCallback(SCDetectRateFilterFunc cb, void *arg); +bool SCDetectEngineRegisterRateFilterCallback(SCDetectRateFilterFunc cb, void *arg); /* Engine groups profiles (low, medium, high, custom) */ enum {