From 2b883b93be5feef26469fb07ca126b7c13b2fd21 Mon Sep 17 00:00:00 2001 From: Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> Date: Sun, 10 Sep 2023 11:09:59 +0200 Subject: Fix some errors found by fuzzers (#2078) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix compilation on Windows. "dirent.h" file has been taken from https://github.com/tronkko/dirent/ Fix Python bindings Fix some warnings with x86_64-w64-mingw32-gcc: ``` protocols/dns.c: In function ‘ndpi_search_dns’: protocols/dns.c:775:41: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast] 775 | unsigned long first_element_len = (unsigned long)dot - (unsigned long)_hostname; | ^ protocols/dns.c:775:62: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast] 775 | unsigned long first_element_len = (unsigned long)dot - (unsigned long)_hostname; | ``` ``` In file included from ndpi_bitmap64.c:31: third_party/include/binaryfusefilter.h: In function ‘binary_fuse8_hash’: third_party/include/binaryfusefilter.h:160:32: error: left shift count >= width of type [-Werror=shift-count-overflow] 160 | uint64_t hh = hash & ((1UL << 36) - 1); ``` ``` In function ‘ndpi_match_custom_category’, inlined from ‘ndpi_fill_protocol_category.part.0’ at ndpi_main.c:7056:16: ndpi_main.c:3419:3: error: ‘strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=] 3419 | strncpy(buf, name, name_len); ``` --- src/lib/ndpi_domain_classify.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/lib/ndpi_domain_classify.c') diff --git a/src/lib/ndpi_domain_classify.c b/src/lib/ndpi_domain_classify.c index fa866f32d..f1a319067 100644 --- a/src/lib/ndpi_domain_classify.c +++ b/src/lib/ndpi_domain_classify.c @@ -47,6 +47,9 @@ ndpi_domain_classify* ndpi_domain_classify_alloc() { void ndpi_domain_classify_free(ndpi_domain_classify *s) { u_int32_t i; + if(!s) + return; + for(i=0; iclasses[i].domains != NULL) { ndpi_bitmap64_free(s->classes[i].domains); @@ -90,6 +93,8 @@ bool ndpi_domain_classify_add(ndpi_domain_classify *s, } else if(s->classes[i].class_id == 0) { s->classes[i].class_id = class_id; s->classes[i].domains = ndpi_bitmap64_alloc(); + if(!s->classes[i].domains) + s->classes[i].class_id = 0; break; } } @@ -117,6 +122,8 @@ u_int32_t ndpi_domain_classify_add_domains(ndpi_domain_classify *s, } else if(s->classes[i].class_id == 0) { s->classes[i].class_id = class_id; s->classes[i].domains = ndpi_bitmap64_alloc(); + if(!s->classes[i].domains) + s->classes[i].class_id = 0; break; } } -- cgit v1.2.3