aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorIvan Nardi <12729895+IvanNardi@users.noreply.github.com>2022-02-21 20:32:50 +0100
committerGitHub <noreply@github.com>2022-02-21 20:32:50 +0100
commitfbb9700086eff42ed315be3d41c97860006ae9ae (patch)
tree31b26a58ab3e161e246b2543f2e56d40bba9f338 /example
parent6c1accd2bdca957b0979707b7f789ae8b5a63334 (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 'example')
-rw-r--r--example/ndpiReader.c2
-rw-r--r--example/reader_util.c5
-rw-r--r--example/reader_util.h2
3 files changed, 5 insertions, 4 deletions
diff --git a/example/ndpiReader.c b/example/ndpiReader.c
index 5f7f5d2b2..e568a2fe7 100644
--- a/example/ndpiReader.c
+++ b/example/ndpiReader.c
@@ -2062,7 +2062,7 @@ static void setupDetection(u_int16_t thread_id, pcap_t * pcap_handle) {
prefs.ignore_vlanid = ignore_vlanid;
memset(&ndpi_thread_info[thread_id], 0, sizeof(ndpi_thread_info[thread_id]));
- ndpi_thread_info[thread_id].workflow = ndpi_workflow_init(&prefs, pcap_handle);
+ ndpi_thread_info[thread_id].workflow = ndpi_workflow_init(&prefs, pcap_handle, 1);
/* Preferences */
ndpi_workflow_set_flow_detected_callback(ndpi_thread_info[thread_id].workflow,
diff --git a/example/reader_util.c b/example/reader_util.c
index 3340170ef..b16a1838c 100644
--- a/example/reader_util.c
+++ b/example/reader_util.c
@@ -391,7 +391,7 @@ extern char *_debug_protocols;
static int _debug_protocols_ok = 0;
struct ndpi_workflow* ndpi_workflow_init(const struct ndpi_workflow_prefs * prefs,
- pcap_t * pcap_handle) {
+ pcap_t * pcap_handle, int do_init_flows_root) {
struct ndpi_detection_module_struct * module;
struct ndpi_workflow * workflow;
@@ -427,7 +427,8 @@ struct ndpi_workflow* ndpi_workflow_init(const struct ndpi_workflow_prefs * pref
if(_debug_protocols_ok)
ndpi_set_debug_bitmask(module, debug_bitmask);
- workflow->ndpi_flows_root = ndpi_calloc(workflow->prefs.num_roots, sizeof(void *));
+ if(do_init_flows_root)
+ workflow->ndpi_flows_root = ndpi_calloc(workflow->prefs.num_roots, sizeof(void *));
return workflow;
}
diff --git a/example/reader_util.h b/example/reader_util.h
index ccfab2433..d96748b9a 100644
--- a/example/reader_util.h
+++ b/example/reader_util.h
@@ -306,7 +306,7 @@ typedef struct ndpi_workflow {
/* TODO: remove wrappers parameters and use ndpi global, when their initialization will be fixed... */
-struct ndpi_workflow * ndpi_workflow_init(const struct ndpi_workflow_prefs * prefs, pcap_t * pcap_handle);
+struct ndpi_workflow * ndpi_workflow_init(const struct ndpi_workflow_prefs * prefs, pcap_t * pcap_handle, int do_init_flows_root);
/* workflow main free function */