diff options
author | Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> | 2023-09-10 11:09:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-10 11:09:59 +0200 |
commit | 2b883b93be5feef26469fb07ca126b7c13b2fd21 (patch) | |
tree | 0f9bbcde2e9d41a86bdce1edfdab1588729c52ae /src/lib/ndpi_bitmap64.c | |
parent | 805df2e5ceebf9252248ac4514d47ba8756c4042 (diff) |
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);
```
Diffstat (limited to 'src/lib/ndpi_bitmap64.c')
-rw-r--r-- | src/lib/ndpi_bitmap64.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/lib/ndpi_bitmap64.c b/src/lib/ndpi_bitmap64.c index 1c8368b29..f254c1483 100644 --- a/src/lib/ndpi_bitmap64.c +++ b/src/lib/ndpi_bitmap64.c @@ -76,6 +76,9 @@ bool ndpi_bitmap64_compress(ndpi_bitmap64 *_b) { ndpi_bitmap64_t *b = (ndpi_bitmap64_t*)_b; u_int32_t i; + if(!b) + return(false); + if(b->num_used_entries > 0) { if(b->num_used_entries > 1) qsort(b->entries, b->num_used_entries, @@ -122,6 +125,9 @@ bool ndpi_bitmap64_compress(ndpi_bitmap64 *_b) { bool ndpi_bitmap64_set(ndpi_bitmap64 *_b, u_int64_t value) { ndpi_bitmap64_t *b = (ndpi_bitmap64_t*)_b; + if(!b) + return(false); + if(b->is_compressed) { /* We need to discard the filter and start over as this @@ -155,6 +161,9 @@ bool ndpi_bitmap64_set(ndpi_bitmap64 *_b, u_int64_t value) { bool ndpi_bitmap64_isset(ndpi_bitmap64 *_b, u_int64_t value) { ndpi_bitmap64_t *b = (ndpi_bitmap64_t*)_b; + if(!b) + return(false); + if(!b->is_compressed) ndpi_bitmap64_compress(b); return(binary_fuse16_contain(value, &b->bitmap)); @@ -165,6 +174,9 @@ bool ndpi_bitmap64_isset(ndpi_bitmap64 *_b, u_int64_t value) { void ndpi_bitmap64_free(ndpi_bitmap64 *_b) { ndpi_bitmap64_t *b = (ndpi_bitmap64_t*)_b; + if(!b) + return; + if(b->entries) ndpi_free(b->entries); if(b->is_compressed) @@ -178,5 +190,8 @@ void ndpi_bitmap64_free(ndpi_bitmap64 *_b) { u_int32_t ndpi_bitmap64_size(ndpi_bitmap64 *_b) { ndpi_bitmap64_t *b = (ndpi_bitmap64_t*)_b; + if(!b) + return(0); + return(sizeof(ndpi_bitmap64) + binary_fuse16_size_in_bytes(&b->bitmap)); } |