]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
fuzz: cleans all flow after one run
authorPhilippe Antoine <contact@catenacyber.fr>
Fri, 21 Jan 2022 12:40:08 +0000 (13:40 +0100)
committerVictor Julien <vjulien@oisf.net>
Tue, 25 Jan 2022 12:23:53 +0000 (13:23 +0100)
Completes commit e2370d6861990e9aba7b551e51cfa04d945f4510
for all the fuzz targets processing pcaps
using a generic function.

FlowShutdown is not used because it uses the loop to destroy
mutexes, which we want to reuse for fuzzing

src/flow.c
src/flow.h
src/tests/fuzz/fuzz_predefpcap_aware.c
src/tests/fuzz/fuzz_sigpcap.c
src/tests/fuzz/fuzz_sigpcap_aware.c

index db90db96af905c394305f7e082402104d6140e1b..c1353a8a31e64a44cd43bc7db765b02fa4d5a1ea 100644 (file)
@@ -646,6 +646,22 @@ void FlowInitConfig(bool quiet)
     return;
 }
 
+void FlowReset(void)
+{
+    // resets the flows (for reuse by fuzzing)
+    for (uint32_t u = 0; u < flow_config.hash_size; u++) {
+        Flow *f = flow_hash[u].head;
+        while (f) {
+            Flow *n = f->next;
+            uint8_t proto_map = FlowGetProtoMapping(f->proto);
+            FlowClearMemory(f, proto_map);
+            FlowFree(f);
+            f = n;
+        }
+        flow_hash[u].head = NULL;
+    }
+}
+
 /** \brief shutdown the flow engine
  *  \warning Not thread safe */
 void FlowShutdown(void)
index 49e564f4f3e4f2012e2e7c1f40577642d206c30e..349ec53e5b7fe4000a15d6d5d5a497706da0ee46 100644 (file)
@@ -555,6 +555,7 @@ void FlowSetupPacket(Packet *p);
 void FlowHandlePacket (ThreadVars *, FlowLookupStruct *, Packet *);
 void FlowInitConfig(bool);
 void FlowPrintQueueInfo (void);
+void FlowReset(void);
 void FlowShutdown(void);
 void FlowSetIPOnlyFlag(Flow *, int);
 void FlowSetHasAlertsFlag(Flow *);
index 4dfc27c4447b27d93da087be18163ec7ca4e8990..b607c51fac09335785c5d66d891bf59d99698e45 100644 (file)
@@ -143,17 +143,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
         p->pcap_cnt = pcap_cnt;
     }
     PacketFree(p);
-    for (uint32_t u = 0; u < flow_config.hash_size; u++) {
-        Flow *f = flow_hash[u].head;
-        while (f) {
-            Flow *n = f->next;
-            uint8_t proto_map = FlowGetProtoMapping(f->proto);
-            FlowClearMemory(f, proto_map);
-            FlowFree(f);
-            f = n;
-        }
-        flow_hash[u].head = NULL;
-    }
+    FlowReset();
 
     return 0;
 }
index 37066b6834b7e37adf99d917353e78653b454449..43ca2e67303101cd0829974ce52f6d7b26e9fbaa 100644 (file)
@@ -22,6 +22,7 @@
 #include "util-unittest-helper.h"
 #include "conf-yaml-loader.h"
 #include "pkt-var.h"
+#include "flow-util.h"
 
 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
 
@@ -185,6 +186,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
     //close structure
     pcap_close(pkts);
     PacketFree(p);
+    FlowReset();
 
     return 0;
 }
index 2c46a098e913c06133534f2dff5fff13c681fa51..2a9403d3049b90e8621c982908de093372368d76 100644 (file)
@@ -22,6 +22,7 @@
 #include "util-unittest-helper.h"
 #include "conf-yaml-loader.h"
 #include "pkt-var.h"
+#include "flow-util.h"
 
 #include <fuzz_pcap.h>
 
@@ -181,6 +182,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
         p->pcap_cnt = pcap_cnt;
     }
     PacketFree(p);
+    FlowReset();
 
     return 0;
 }