diff options
author | Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> | 2023-04-25 16:37:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-25 16:37:28 +0200 |
commit | 40b6d5a2e193322e6e93b2eeb087c51d8eb6faad (patch) | |
tree | cb5a338df534f710c74107717cc9be54c07211ac /src | |
parent | de693cbbc91d4144b8d67a8c99c565ea21cece09 (diff) |
fuzz: extend fuzzers coverage (#1952)
Diffstat (limited to 'src')
-rw-r--r-- | src/include/ndpi_classify.h | 8 | ||||
-rw-r--r-- | src/include/ndpi_main.h | 2 | ||||
-rw-r--r-- | src/include/ndpi_protocols.h | 3 | ||||
-rw-r--r-- | src/lib/ndpi_analyze.c | 7 | ||||
-rw-r--r-- | src/lib/ndpi_classify.c | 6 | ||||
-rw-r--r-- | src/lib/ndpi_main.c | 12 | ||||
-rw-r--r-- | src/lib/ndpi_utils.c | 20 |
7 files changed, 33 insertions, 25 deletions
diff --git a/src/include/ndpi_classify.h b/src/include/ndpi_classify.h index 0980985ef..2bd76df6a 100644 --- a/src/include/ndpi_classify.h +++ b/src/include/ndpi_classify.h @@ -45,6 +45,10 @@ #include "ndpi_includes.h" +#ifdef __cplusplus +extern "C" { +#endif + /* constants */ #define NUM_PARAMETERS_SPLT_LOGREG 208 #define NUM_PARAMETERS_BD_LOGREG 464 @@ -89,4 +93,8 @@ u_int64_t ndpi_timeval_to_milliseconds(pkt_timeval ts); u_int64_t ndpi_timeval_to_microseconds(pkt_timeval ts); void ndpi_log_timestamp(char *log_ts, u_int32_t log_ts_len); +#ifdef __cplusplus +} +#endif + #endif /* NDPI_CLASSIFY_H */ diff --git a/src/include/ndpi_main.h b/src/include/ndpi_main.h index c9d7ac3f9..b4ef20f5f 100644 --- a/src/include/ndpi_main.h +++ b/src/include/ndpi_main.h @@ -95,7 +95,7 @@ extern "C" { struct ndpi_flow_struct *flow); extern u_int16_t ndpi_check_for_email_address(struct ndpi_detection_module_struct *ndpi_struct, - u_int16_t counter); + u_int16_t counter); extern void ndpi_int_change_category(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow, diff --git a/src/include/ndpi_protocols.h b/src/include/ndpi_protocols.h index 20804a632..b97726080 100644 --- a/src/include/ndpi_protocols.h +++ b/src/include/ndpi_protocols.h @@ -43,6 +43,9 @@ ndpi_port_range* ndpi_build_default_ports(ndpi_port_range *ports, u_int16_t portE); /* TCP/UDP protocols */ +#ifdef __cplusplus +extern "C" +#endif u_int ndpi_search_tcp_or_udp_raw(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow, u_int8_t protocol, diff --git a/src/lib/ndpi_analyze.c b/src/lib/ndpi_analyze.c index 178097b9f..346e65a48 100644 --- a/src/lib/ndpi_analyze.c +++ b/src/lib/ndpi_analyze.c @@ -1096,6 +1096,7 @@ int ndpi_hw_init(struct ndpi_hw_struct *hw, if((hw->s = (double*)ndpi_calloc(hw->params.num_season_periods, sizeof(double))) == NULL) { ndpi_free(hw->y); + hw->y = NULL; return(-1); } @@ -1213,8 +1214,10 @@ void ndpi_hw_reset(struct ndpi_hw_struct *hw) { hw->num_values = 0; hw->u = hw->v = hw->sum_square_error = 0; - memset(&hw->y, 0, (hw->params.num_season_periods * sizeof(u_int64_t))); - memset(&hw->s, 0, (hw->params.num_season_periods * sizeof(double))); + if(hw->y) + memset(hw->y, 0, (hw->params.num_season_periods * sizeof(u_int64_t))); + if(hw->s) + memset(hw->s, 0, (hw->params.num_season_periods * sizeof(double))); } /* ********************************************************************************* */ diff --git a/src/lib/ndpi_classify.c b/src/lib/ndpi_classify.c index f1037411d..3dba2207e 100644 --- a/src/lib/ndpi_classify.c +++ b/src/lib/ndpi_classify.c @@ -268,10 +268,12 @@ ndpi_merge_splt_arrays (const uint16_t *pkt_len, const pkt_timeval *pkt_time, uint16_t *merged_lens, uint16_t *merged_times) { int s,r; - pkt_timeval ts_start = { 0, 0 }; /* initialize to avoid spurious warnings */ + pkt_timeval ts_start; pkt_timeval tmp, tmp_r; pkt_timeval start_m; + ndpi_timer_clear(&ts_start); + if(r_idx + s_idx == 0) { return ; } else if(r_idx == 0) { @@ -677,7 +679,7 @@ ndpi_timeval_to_microseconds(pkt_timeval ts) { u_int64_t sec = ts.tv_sec; u_int64_t usec = ts.tv_usec; - return usec + sec * 1000 * 1000;; + return usec + sec * 1000 * 1000; } /* **************************************** */ diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index 6b2210ec1..4d83def4d 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -2287,7 +2287,7 @@ u_int16_t ndpi_network_ptree_match(struct ndpi_detection_module_struct *ndpi_str ndpi_prefix_t prefix; ndpi_patricia_node_t *node; - if(!ndpi_str->protocols_ptree) + if(!ndpi_str || !ndpi_str->protocols_ptree) return(NDPI_PROTOCOL_UNKNOWN); if(ndpi_str->ndpi_num_custom_protocols == 0) { @@ -2318,7 +2318,7 @@ u_int16_t ndpi_network_port_ptree_match(struct ndpi_detection_module_struct *ndp ndpi_prefix_t prefix; ndpi_patricia_node_t *node; - if(!ndpi_str->protocols_ptree) + if(!ndpi_str || !ndpi_str->protocols_ptree) return(NDPI_PROTOCOL_UNKNOWN); if(ndpi_str->ndpi_num_custom_protocols == 0) { @@ -7498,8 +7498,12 @@ void ndpi_parse_packet_line_info_any(struct ndpi_detection_module_struct *ndpi_s u_int16_t ndpi_check_for_email_address(struct ndpi_detection_module_struct *ndpi_str, u_int16_t counter) { - struct ndpi_packet_struct *packet = &ndpi_str->packet; + struct ndpi_packet_struct *packet; + + if(!ndpi_str) + return(0); + packet = &ndpi_str->packet; NDPI_LOG_DBG2(ndpi_str, "called ndpi_check_for_email_address\n"); if(packet->payload_packet_len > counter && ((packet->payload[counter] >= 'a' && packet->payload[counter] <= 'z') || @@ -8983,7 +8987,7 @@ const char *ndpi_get_l4_proto_name(ndpi_l4_proto_info proto) { ndpi_l4_proto_info ndpi_get_l4_proto_info(struct ndpi_detection_module_struct *ndpi_struct, u_int16_t ndpi_proto_id) { - if(ndpi_proto_id < ndpi_struct->ndpi_num_supported_protocols) { + if(ndpi_struct && ndpi_proto_id < ndpi_struct->ndpi_num_supported_protocols) { u_int16_t idx = ndpi_struct->proto_defaults[ndpi_proto_id].protoIdx; NDPI_SELECTION_BITMASK_PROTOCOL_SIZE bm = ndpi_struct->callback_buffer[idx].ndpi_selection_bitmask; diff --git a/src/lib/ndpi_utils.c b/src/lib/ndpi_utils.c index 8f89ef7bf..343c5b0f0 100644 --- a/src/lib/ndpi_utils.c +++ b/src/lib/ndpi_utils.c @@ -2018,39 +2018,30 @@ const char* ndpi_risk2str(ndpi_risk_enum risk) { case NDPI_POSSIBLE_EXPLOIT: return("Possible Exploit"); - break; case NDPI_TLS_CERTIFICATE_ABOUT_TO_EXPIRE: return("TLS Cert About To Expire"); - break; case NDPI_PUNYCODE_IDN: return("IDN Domain Name"); - break; case NDPI_ERROR_CODE_DETECTED: return("Error Code"); - break; case NDPI_HTTP_CRAWLER_BOT: return("Crawler/Bot"); - break; case NDPI_ANONYMOUS_SUBSCRIBER: return("Anonymous Subscriber"); - break; case NDPI_UNIDIRECTIONAL_TRAFFIC: return("Unidirectional Traffic"); - break; case NDPI_HTTP_OBSOLETE_SERVER: return("HTTP Obsolete Server"); - break; case NDPI_PERIODIC_FLOW: return("Periodic Flow"); - break; case NDPI_MINOR_ISSUES: return("Minor Issues"); @@ -2070,27 +2061,21 @@ const char* ndpi_severity2str(ndpi_risk_severity s) { switch(s) { case NDPI_RISK_LOW: return("Low"); - break; case NDPI_RISK_MEDIUM: return("Medium"); - break; case NDPI_RISK_HIGH: return("High"); - break; case NDPI_RISK_SEVERE: return("Severe"); - break; case NDPI_RISK_CRITICAL: return("Critical"); - break; case NDPI_RISK_EMERGENCY: return("Emergency"); - break; } return(""); @@ -2367,7 +2352,7 @@ static u_int8_t ndpi_check_hostname_risk_exception(struct ndpi_detection_module_ ndpi_automa *automa = &ndpi_str->host_risk_mask_automa; u_int8_t ret = 0; - if(automa->ac_automa) { + if(automa && automa->ac_automa) { AC_TEXT_t ac_input_text; AC_REP_t match; @@ -2880,6 +2865,9 @@ u_int8_t ndpi_check_flow_risk_exceptions(struct ndpi_detection_module_struct *nd ndpi_risk_params params[]) { u_int i; + if(!ndpi_str) + return(0); + for(i=0; i<num_params; i++) { switch(params[i].id) { case NDPI_PARAM_HOSTNAME: |