From 3a16009966d5f98f49f8b9bd689d9d9da7e939c5 Mon Sep 17 00:00:00 2001 From: Alexander Gozman Date: Mon, 6 May 2019 19:10:52 +0300 Subject: [PATCH] Bug #2965: fix NFQ arguments parsing --- src/source-nfq.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/source-nfq.c b/src/source-nfq.c index 8c4273b6a4..aeb80f048e 100644 --- a/src/source-nfq.c +++ b/src/source-nfq.c @@ -917,21 +917,25 @@ int NFQParseAndRegisterQueues(const char *queues) num_queues = queue_end - queue_start + 1; // +1 due to inclusive range } - g_nfq_t = (NFQThreadVars *)SCCalloc(num_queues, sizeof(NFQThreadVars)); - - if (g_nfq_t == NULL) { + // We do realloc() to preserve previously registered queues + void *ptmp = SCRealloc(g_nfq_t, (receive_queue_num + num_queues) * sizeof(NFQThreadVars)); + if (ptmp == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate NFQThreadVars"); + NFQContextsClean(); exit(EXIT_FAILURE); } - g_nfq_q = (NFQQueueVars *)SCCalloc(num_queues, sizeof(NFQQueueVars)); + g_nfq_t = (NFQThreadVars *)ptmp; - if (g_nfq_q == NULL) { + ptmp = SCRealloc(g_nfq_q, (receive_queue_num + num_queues) * sizeof(NFQQueueVars)); + if (ptmp == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate NFQQueueVars"); - SCFree(g_nfq_t); + NFQContextsClean(); exit(EXIT_FAILURE); } + g_nfq_q = (NFQQueueVars *)ptmp; + do { if (NFQRegisterQueue(queue_start) != 0) { return -1;