Fix some errors found by fuzzers (#2078)
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); ```
This commit is contained in:
+3
-3
@@ -157,7 +157,7 @@ static inline uint32_t binary_fuse8_hash(int index, uint64_t hash,
|
||||
uint64_t h = binary_fuse_mulhi(hash, filter->SegmentCountLength);
|
||||
h += index * filter->SegmentLength;
|
||||
// keep the lower 36 bits
|
||||
uint64_t hh = hash & ((1UL << 36) - 1);
|
||||
uint64_t hh = hash & ((1ULL << 36) - 1);
|
||||
// index 0: right shift by 36; index 1: right shift by 18; index 2: no shift
|
||||
h ^= (size_t)((hh >> (36 - 18 * index)) & filter->SegmentLengthMask);
|
||||
return h;
|
||||
@@ -477,7 +477,7 @@ static inline uint32_t binary_fuse16_hash(int index, uint64_t hash,
|
||||
uint64_t h = binary_fuse_mulhi(hash, filter->SegmentCountLength);
|
||||
h += index * filter->SegmentLength;
|
||||
// keep the lower 36 bits
|
||||
uint64_t hh = hash & ((1UL << 36) - 1);
|
||||
uint64_t hh = hash & ((1ULL << 36) - 1);
|
||||
// index 0: right shift by 36; index 1: right shift by 18; index 2: no shift
|
||||
h ^= (size_t)((hh >> (36 - 18 * index)) & filter->SegmentLengthMask);
|
||||
return h;
|
||||
@@ -522,7 +522,7 @@ static inline bool binary_fuse16_allocate(uint32_t size,
|
||||
filter->ArrayLength =
|
||||
(filter->SegmentCount + arity - 1) * filter->SegmentLength;
|
||||
filter->SegmentCountLength = filter->SegmentCount * filter->SegmentLength;
|
||||
filter->Fingerprints = (uint16_t*)ndpi_malloc(filter->ArrayLength * sizeof(uint16_t));
|
||||
filter->Fingerprints = (uint16_t*)ndpi_calloc(filter->ArrayLength, sizeof(uint16_t));
|
||||
return filter->Fingerprints != NULL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user