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

SCDetectEngineRegisterRateFilterCallback() dereferences the result of
DetectEngineGetCurrent() unconditionally. Add a NULL guard with
SCLogError and return false so callers can detect registration failure.

Flagged by Svace and confirmed by gcc -fanalyzer.

Ticket: 8560
pull/15601/head
Denis Balashov 3 months ago committed by Victor Julien
parent 4d4c6227e1
commit 17151571b8

@ -5203,12 +5203,17 @@ 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)

@ -1214,7 +1214,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 {

Loading…
Cancel
Save