From b9fca3ece688c647c7d4f0119ecbd0ead6161f19 Mon Sep 17 00:00:00 2001 From: Nardi Ivan Date: Tue, 9 Jan 2024 10:24:36 +0100 Subject: [PATCH] Make `ndpi_finalize_initialization()` returns an error code We should check if the initialization was fine or not --- example/ndpiReader.c | 9 ++++++--- src/include/ndpi_api.h | 4 +++- src/lib/ndpi_main.c | 10 +++++----- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/example/ndpiReader.c b/example/ndpiReader.c index 27b7afd73615..06097d5806b8 100644 --- a/example/ndpiReader.c +++ b/example/ndpiReader.c @@ -2817,7 +2817,7 @@ static void on_protocol_discovered(struct ndpi_workflow * workflow, static void setupDetection(u_int16_t thread_id, pcap_t * pcap_handle) { NDPI_PROTOCOL_BITMASK enabled_bitmask; struct ndpi_workflow_prefs prefs; - int i; + int i, ret; ndpi_cfg_error rc; memset(&prefs, 0, sizeof(prefs)); @@ -2917,8 +2917,11 @@ static void setupDetection(u_int16_t thread_id, pcap_t * pcap_handle) { cfgs[i].proto, cfgs[i].param, cfgs[i].value, rc); } - - ndpi_finalize_initialization(ndpi_thread_info[thread_id].workflow->ndpi_struct); + ret = ndpi_finalize_initialization(ndpi_thread_info[thread_id].workflow->ndpi_struct); + if(ret != 0) { + fprintf(stderr, "Error ndpi_finalize_initialization: %d\n", ret); + exit(-1); + } if(enable_doh_dot_detection) ndpi_set_detection_preferences(ndpi_thread_info[thread_id].workflow->ndpi_struct, ndpi_pref_enable_tls_block_dissection, 1); diff --git a/src/include/ndpi_api.h b/src/include/ndpi_api.h index 7dc25f0d06b9..8c44cec0ac4f 100644 --- a/src/include/ndpi_api.h +++ b/src/include/ndpi_api.h @@ -222,8 +222,10 @@ extern "C" { * * @par ndpi_str = the struct created for the protocol detection * + * @return 0 on success + * */ - void ndpi_finalize_initialization(struct ndpi_detection_module_struct *ndpi_str); + int ndpi_finalize_initialization(struct ndpi_detection_module_struct *ndpi_str); /** * Frees the dynamic memory allocated members in the specified flow diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index 2db955822477..a5bdb66d14d6 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -3510,13 +3510,13 @@ static void ndpi_add_domain_risk_exceptions(struct ndpi_detection_module_struct /* *********************************************** */ -void ndpi_finalize_initialization(struct ndpi_detection_module_struct *ndpi_str) { +int ndpi_finalize_initialization(struct ndpi_detection_module_struct *ndpi_str) { u_int i; if(!ndpi_str) - return; + return -1; if(ndpi_str->finalized) /* Already finalized */ - return; + return 0; ndpi_add_domain_risk_exceptions(ndpi_str); @@ -3585,7 +3585,7 @@ void ndpi_finalize_initialization(struct ndpi_detection_module_struct *ndpi_str) } } - if(ndpi_str->ac_automa_finalized) return; + if(ndpi_str->ac_automa_finalized) return -1; ndpi_automa * const automa[] = { &ndpi_str->host_automa, &ndpi_str->tls_cert_subject_automa, @@ -3603,7 +3603,7 @@ void ndpi_finalize_initialization(struct ndpi_detection_module_struct *ndpi_str) ndpi_str->finalized = 1; - return; + return 0; } /* *********************************************** */