}
}
+/**
+ * \brief Realloc threshold context hash tables
+ *
+ * \param de_ctx Detection Context
+ */
+void ThresholdHashRealloc(DetectEngineCtx *de_ctx)
+{
+ /* Return if we are already big enough */
+ uint32_t num = de_ctx->signum + 1;
+ if (num <= de_ctx->ths_ctx.th_size)
+ return;
+
+ void *ptmp = SCRealloc(de_ctx->ths_ctx.th_entry, num * sizeof(DetectThresholdEntry *));
+ if (ptmp == NULL) {
+ SCLogWarning(SC_ERR_MEM_ALLOC, "Error allocating memory for rule thresholds"
+ " (tried to allocate %"PRIu32" th_entrys for rule tracking)", num);
+ } else {
+ de_ctx->ths_ctx.th_entry = ptmp;
+ for (uint32_t i = de_ctx->ths_ctx.th_size; i < num; ++i) {
+ de_ctx->ths_ctx.th_entry[i] = NULL;
+ }
+ de_ctx->ths_ctx.th_size = num;
+ }
+}
+
/**
* \brief Destroy threshold context hash tables
*
#include "detect.h"
#include "detect-engine.h"
#include "detect-engine-address.h"
+#include "detect-engine-threshold.h"
#include "detect-threshold.h"
#include "detect-parse.h"
Signature *s = NULL;
SigMatch *sm = NULL;
DetectThresholdData *de = NULL;
- void *ptmp;
BUG_ON(parsed_type == TYPE_SUPPRESS);
sm->ctx = (void *)de;
if (parsed_track == TRACK_RULE) {
- ptmp = SCRealloc(de_ctx->ths_ctx.th_entry, (de_ctx->ths_ctx.th_size + 1) * sizeof(DetectThresholdEntry *));
- if (ptmp == NULL) {
- SCFree(de_ctx->ths_ctx.th_entry);
- de_ctx->ths_ctx.th_entry = NULL;
- SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory for threshold config"
- " (tried to allocate %"PRIu32"th_entrys for rule tracking with rate_filter)", de_ctx->ths_ctx.th_size + 1);
- } else {
- de_ctx->ths_ctx.th_entry = ptmp;
- de_ctx->ths_ctx.th_entry[de_ctx->ths_ctx.th_size] = NULL;
- de_ctx->ths_ctx.th_size++;
- }
+ ThresholdHashRealloc(de_ctx);
}
SigMatchAppendSMToList(s, sm, DETECT_SM_LIST_THRESHOLD);
}
sm->ctx = (void *)de;
if (parsed_track == TRACK_RULE) {
- ptmp = SCRealloc(de_ctx->ths_ctx.th_entry, (de_ctx->ths_ctx.th_size + 1) * sizeof(DetectThresholdEntry *));
- if (ptmp == NULL) {
- SCFree(de_ctx->ths_ctx.th_entry);
- de_ctx->ths_ctx.th_entry = NULL;
- SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory for threshold config"
- " (tried to allocate %"PRIu32"th_entrys for rule tracking with rate_filter)", de_ctx->ths_ctx.th_size + 1);
- } else {
- de_ctx->ths_ctx.th_entry = ptmp;
- de_ctx->ths_ctx.th_entry[de_ctx->ths_ctx.th_size] = NULL;
- de_ctx->ths_ctx.th_size++;
- }
+ ThresholdHashRealloc(de_ctx);
}
SigMatchAppendSMToList(s, sm, DETECT_SM_LIST_THRESHOLD);
}
sm->ctx = (void *)de;
if (parsed_track == TRACK_RULE) {
- ptmp = SCRealloc(de_ctx->ths_ctx.th_entry, (de_ctx->ths_ctx.th_size + 1) * sizeof(DetectThresholdEntry *));
- if (ptmp == NULL) {
- SCFree(de_ctx->ths_ctx.th_entry);
- de_ctx->ths_ctx.th_entry = NULL;
- SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory for threshold config"
- " (tried to allocate %"PRIu32"th_entrys for rule tracking with rate_filter)", de_ctx->ths_ctx.th_size + 1);
- } else {
- de_ctx->ths_ctx.th_entry = ptmp;
- de_ctx->ths_ctx.th_entry[de_ctx->ths_ctx.th_size] = NULL;
- de_ctx->ths_ctx.th_size++;
- }
+ ThresholdHashRealloc(de_ctx);
}
SigMatchAppendSMToList(s, sm, DETECT_SM_LIST_THRESHOLD);