From ef6085370f75ae7c6c53bfbd0e36c588483a5047 Mon Sep 17 00:00:00 2001 From: Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> Date: Sun, 10 Sep 2023 18:44:50 +0200 Subject: fuzz: add fuzzers to test bitmap64 and domain_classify data structures (#2082) --- src/lib/ndpi_bitmap64.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/lib/ndpi_bitmap64.c') diff --git a/src/lib/ndpi_bitmap64.c b/src/lib/ndpi_bitmap64.c index f254c1483..6403eea7a 100644 --- a/src/lib/ndpi_bitmap64.c +++ b/src/lib/ndpi_bitmap64.c @@ -79,6 +79,9 @@ bool ndpi_bitmap64_compress(ndpi_bitmap64 *_b) { if(!b) return(false); + if(b->is_compressed) + return(true); + if(b->num_used_entries > 0) { if(b->num_used_entries > 1) qsort(b->entries, b->num_used_entries, @@ -110,10 +113,13 @@ bool ndpi_bitmap64_compress(ndpi_bitmap64 *_b) { if(binary_fuse16_populate(b->entries, b->num_used_entries, &b->bitmap)) { ndpi_free(b->entries), b->num_used_entries = b->num_allocated_entries = 0; b->entries = NULL; - } else + } else { + binary_fuse16_free(&b->bitmap); return(false); - } else + } + } else { return(false); + } b->is_compressed = true; @@ -145,7 +151,10 @@ bool ndpi_bitmap64_set(ndpi_bitmap64 *_b, u_int64_t value) { rc = (u_int64_t*)ndpi_realloc(b->entries, sizeof(u_int64_t)*b->num_allocated_entries, sizeof(u_int64_t)*new_len); - if(rc == NULL) return(false); + if(rc == NULL) { + b->is_compressed = false; + return(false); + } b->entries = rc, b->num_allocated_entries = new_len; } @@ -165,6 +174,8 @@ bool ndpi_bitmap64_isset(ndpi_bitmap64 *_b, u_int64_t value) { return(false); if(!b->is_compressed) ndpi_bitmap64_compress(b); + if(!b->is_compressed) + return(false); return(binary_fuse16_contain(value, &b->bitmap)); } -- cgit v1.2.3