]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Bug #2965: fix NFQ arguments parsing 3868/head
authorAlexander Gozman <goal81@gmail.com>
Mon, 6 May 2019 16:10:52 +0000 (19:10 +0300)
committerVictor Julien <victor@inliniac.net>
Sat, 18 May 2019 05:42:59 +0000 (07:42 +0200)
src/source-nfq.c

index 8c4273b6a45727847b953430b29032c64029a594..aeb80f048e406b05ec55b6dee87bd6517762c850 100644 (file)
@@ -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;