Small fixes after API cleanup done in c63446e59 (#2449)

This commit is contained in:
Ivan Nardi
2024-05-20 19:06:24 +02:00
committed by GitHub
parent 2093ac5bf6
commit 399be12585
3 changed files with 20 additions and 9 deletions
+3 -4
View File
@@ -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>();
+16 -4
View File
@@ -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;
@@ -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)