fuzz: cleans all flow after one run

Completes commit e2370d6861
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
pull/6861/head
Philippe Antoine 4 years ago committed by Victor Julien
parent 40c315aa35
commit 749b9c7635

@ -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)

@ -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 *);

@ -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;
}

@ -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;
}

@ -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;
}

Loading…
Cancel
Save