diff options
author | Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> | 2022-02-21 20:32:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-21 20:32:50 +0100 |
commit | fbb9700086eff42ed315be3d41c97860006ae9ae (patch) | |
tree | 31b26a58ab3e161e246b2543f2e56d40bba9f338 /fuzz | |
parent | 6c1accd2bdca957b0979707b7f789ae8b5a63334 (diff) |
fuzz: purge old sessions (#1451)
At every fuzz iteration (i.e for every trace file):
* keep the same ndpi context (`ndpi_init_detection_module` is very
slow);
* reset the flow table, otherwise it grows indefinitely.
This change should fix the "out-of-memory" errors reported by oss-fuzz.
Diffstat (limited to 'fuzz')
-rw-r--r-- | fuzz/fuzz_ndpi_reader.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/fuzz/fuzz_ndpi_reader.c b/fuzz/fuzz_ndpi_reader.c index 3989accbc..878896bca 100644 --- a/fuzz/fuzz_ndpi_reader.c +++ b/fuzz/fuzz_ndpi_reader.c @@ -47,6 +47,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { char errbuf[PCAP_ERRBUF_SIZE]; NDPI_PROTOCOL_BITMASK all; char * pcap_path = tempnam("/tmp", "fuzz-ndpi-reader"); + u_int i; if (prefs == NULL) { prefs = calloc(sizeof(struct ndpi_workflow_prefs), 1); @@ -59,7 +60,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { prefs->max_ndpi_flows = 1024 * 1024; prefs->quiet_mode = 0; - workflow = ndpi_workflow_init(prefs, NULL /* pcap handler will be set later */); + workflow = ndpi_workflow_init(prefs, NULL /* pcap handler will be set later */, 0); // enable all protocols NDPI_BITMASK_SET_ALL(all); ndpi_set_protocol_detection_bitmask2(workflow->ndpi_struct, &all); @@ -90,6 +91,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { } workflow->pcap_handle = pkts; + /* Init flow tree */ + workflow->ndpi_flows_root = ndpi_calloc(workflow->prefs.num_roots, sizeof(void *)); header = NULL; r = pcap_next_ex(pkts, &header, &pkt); @@ -109,6 +112,11 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { } pcap_close(pkts); + /* Free flow trees */ + for(i = 0; i < workflow->prefs.num_roots; i++) + ndpi_tdestroy(workflow->ndpi_flows_root[i], ndpi_flow_info_freer); + ndpi_free(workflow->ndpi_flows_root); + remove(pcap_path); free(pcap_path); |