From: Alexander Gozman Date: Mon, 6 May 2019 16:10:52 +0000 (+0300) Subject: Bug #2965: fix NFQ arguments parsing X-Git-Tag: suricata-5.0.0-rc1~473 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3a16009966d5f98f49f8b9bd689d9d9da7e939c5;p=thirdparty%2Fsuricata.git Bug #2965: fix NFQ arguments parsing --- 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;