commandline: add alert-queue expand failure option

For testing purposes. Meant to simulate a reallocation failure when
dynamically growing the alert queue in DetectEngineThreadCtx, so we can
check that Suri's behavior doesn't break under such circumstances.

Task #5319
pull/7670/head
Juliana Fajardini 3 years ago committed by Victor Julien
parent ebc2714e07
commit 58928b249d

@ -27,6 +27,10 @@
#include "flow.h"
#include "flow-private.h"
#ifdef DEBUG
#include "util-exception-policy.h"
#endif
#include "util-profiling.h"
/** tag signature we use for tag alerts */
@ -224,6 +228,10 @@ void AlertQueueFree(DetectEngineThreadCtx *det_ctx)
*/
static uint16_t AlertQueueExpand(DetectEngineThreadCtx *det_ctx)
{
#ifdef DEBUG
if (unlikely(g_eps_is_alert_queue_fail_mode))
return det_ctx->alert_queue_capacity;
#endif
uint16_t new_cap = det_ctx->alert_queue_capacity * 2;
void *tmp_queue = SCRealloc(det_ctx->alert_queue, (size_t)(sizeof(PacketAlert) * new_cap));
if (unlikely(tmp_queue == NULL)) {

@ -1363,6 +1363,7 @@ static TmEcode ParseCommandLine(int argc, char** argv, SCInstance *suri)
{"simulate-packet-tcp-reassembly-memcap", required_argument, 0, 0},
{"simulate-packet-tcp-ssn-memcap", required_argument, 0, 0},
{"simulate-packet-defrag-memcap", required_argument, 0, 0},
{"simulate-alert-queue-realloc-failure", 0, 0, 0},
{NULL, 0, NULL, 0}
};

@ -124,6 +124,7 @@ uint64_t g_eps_stream_ssn_memcap = UINT64_MAX;
uint64_t g_eps_stream_reassembly_memcap = UINT64_MAX;
uint64_t g_eps_flow_memcap = UINT64_MAX;
uint64_t g_eps_defrag_memcap = UINT64_MAX;
bool g_eps_is_alert_queue_fail_mode = false;
/* 1: parsed, 0: not for us, -1: error */
int ExceptionSimulationCommandlineParser(const char *name, const char *arg)
@ -177,6 +178,8 @@ int ExceptionSimulationCommandlineParser(const char *name, const char *arg)
return TM_ECODE_FAILED;
}
g_eps_defrag_memcap = pkt_num;
} else if (strcmp(name, "simulate-alert-queue-realloc-failure") == 0) {
g_eps_is_alert_queue_fail_mode = true;
} else {
// not for us
return 0;

@ -43,6 +43,7 @@ extern uint64_t g_eps_stream_ssn_memcap;
extern uint64_t g_eps_stream_reassembly_memcap;
extern uint64_t g_eps_flow_memcap;
extern uint64_t g_eps_defrag_memcap;
extern bool g_eps_is_alert_queue_fail_mode;
#endif
int ExceptionSimulationCommandlineParser(const char *name, const char *arg);

Loading…
Cancel
Save