diff options
author | Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> | 2024-05-20 19:06:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-20 19:06:24 +0200 |
commit | 399be12585f83302178175396bcaf4487ffd57a9 (patch) | |
tree | fac7e82eda2a7954338d5038b0c84518bb51d89d | |
parent | 2093ac5bf6444db290cdf1c7d64cf4b80f415d2f (diff) |
Small fixes after API cleanup done in c63446e59 (#2449)
-rw-r--r-- | fuzz/fuzz_ds_ptree.cpp | 7 | ||||
-rw-r--r-- | src/lib/ndpi_main.c | 20 | ||||
-rw-r--r-- | tests/cfgs/flow_risk_lists_disable/result/protonvpn.pcap.out | 2 |
3 files changed, 20 insertions, 9 deletions
diff --git a/fuzz/fuzz_ds_ptree.cpp b/fuzz/fuzz_ds_ptree.cpp index 6659fccc8..dfd723d33 100644 --- a/fuzz/fuzz_ds_ptree.cpp +++ b/fuzz/fuzz_ds_ptree.cpp @@ -50,10 +50,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { } /* Some higher level functions */ - ndpi_load_ipv4_ptree_file(t, "ipv4_addresses.txt", NDPI_PROTOCOL_TLS); - ndpi_load_ipv4_ptree_file(t, "invalid_filename", NDPI_PROTOCOL_TLS); - ndpi_load_ipv6_ptree_file(t, "ipv6_addresses.txt", NDPI_PROTOCOL_TLS); - ndpi_load_ipv6_ptree_file(t, "invalid_filename", NDPI_PROTOCOL_TLS); + ndpi_load_ptree_file(t, "ipv4_addresses.txt", NDPI_PROTOCOL_TLS); + ndpi_load_ptree_file(t, "invalid_filename", NDPI_PROTOCOL_TLS); + ndpi_load_ptree_file(t, "ipv6_addresses.txt", NDPI_PROTOCOL_TLS); /* Random search */ num_iteration = fuzzed_data.ConsumeIntegral<u_int8_t>(); diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index c698bcb83..aca43f8f1 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -2428,26 +2428,38 @@ int ndpi_get_patricia_stats(struct ndpi_detection_module_struct *ndpi_struct, switch(ptree_type) { case NDPI_PTREE_RISK_MASK: + if(!ndpi_struct->ip_risk_mask) + return -1; ndpi_patricia_get_stats(ndpi_struct->ip_risk_mask->v4, stats); return 0; case NDPI_PTREE_RISK_MASK6: + if(!ndpi_struct->ip_risk_mask) + return -1; ndpi_patricia_get_stats(ndpi_struct->ip_risk_mask->v6, stats); return 0; case NDPI_PTREE_RISK: + if(!ndpi_struct->ip_risk) + return -1; ndpi_patricia_get_stats(ndpi_struct->ip_risk->v4, stats); return 0; case NDPI_PTREE_RISK6: + if(!ndpi_struct->ip_risk) + return -1; ndpi_patricia_get_stats(ndpi_struct->ip_risk->v6, stats); return 0; case NDPI_PTREE_PROTOCOLS: + if(!ndpi_struct->protocols) + return -1; ndpi_patricia_get_stats(ndpi_struct->protocols->v4, stats); return 0; case NDPI_PTREE_PROTOCOLS6: + if(!ndpi_struct->protocols) + return -1; ndpi_patricia_get_stats(ndpi_struct->protocols->v6, stats); return 0; @@ -4469,14 +4481,14 @@ int ndpi_add_ip_risk_mask(struct ndpi_detection_module_struct *ndpi_str, cidr = strtok_r(NULL, "\n", &saveptr); - if(!is_ipv6 && ndpi_str->ip_risk_mask) { + if(!is_ipv6 && ndpi_str->ip_risk_mask && ndpi_str->ip_risk_mask->v4) { struct in_addr pin; if(inet_pton(AF_INET, addr, &pin) != 1) return(-1); node = add_to_ptree(ndpi_str->ip_risk_mask->v4, AF_INET, &pin, cidr ? atoi(cidr) : 32 /* bits */); - } else if(is_ipv6 && ndpi_str->ip_risk_mask->v6) { + } else if(is_ipv6 && ndpi_str->ip_risk_mask && ndpi_str->ip_risk_mask->v6) { struct in6_addr pin6; if(inet_pton(AF_INET6, addr, &pin6) != 1) @@ -8528,7 +8540,7 @@ static ndpi_protocol ndpi_internal_detection_process_packet(struct ndpi_detectio /* Right now, all the 3 supported risks are only about the *client* ip. Don't check the server ip, to try avoiding false positives */ - if(ndpi_str->ip_risk + if(ndpi_str->ip_risk && ndpi_str->ip_risk->v4 && packet->iph && ndpi_is_public_ipv4(ntohl(packet->iph->saddr)) && ndpi_is_public_ipv4(ntohl(packet->iph->daddr))) { @@ -8536,7 +8548,7 @@ static ndpi_protocol ndpi_internal_detection_process_packet(struct ndpi_detectio addr.s_addr = flow->c_address.v4; net_risk = ndpi_network_risk_ptree_match(ndpi_str, &addr); - } else if(ndpi_str->ip_risk->v6 && + } else if(ndpi_str->ip_risk && ndpi_str->ip_risk->v6 && packet->iphv6) { /* TODO: some checks on "local" addresses? */ struct in6_addr addr; diff --git a/tests/cfgs/flow_risk_lists_disable/result/protonvpn.pcap.out b/tests/cfgs/flow_risk_lists_disable/result/protonvpn.pcap.out index 6a328115b..3472823bf 100644 --- a/tests/cfgs/flow_risk_lists_disable/result/protonvpn.pcap.out +++ b/tests/cfgs/flow_risk_lists_disable/result/protonvpn.pcap.out @@ -4,7 +4,7 @@ DPI Packets (TCP): 12 (6.00 pkts/flow) DPI Packets (UDP): 2 (2.00 pkts/flow) Confidence Match by port : 1 (flows) Confidence DPI : 2 (flows) -Num dissector calls: 152 (50.67 diss/flow) +Num dissector calls: 149 (49.67 diss/flow) LRU cache ookla: 0/0/0 (insert/search/found) LRU cache bittorrent: 0/6/0 (insert/search/found) LRU cache stun: 0/0/0 (insert/search/found) |