fuzz: add fuzzers to test bitmap64 and domain_classify data structures (#2082)
This commit is contained in:
@@ -1800,12 +1800,12 @@ extern "C" {
|
||||
|
||||
/* ******************************* */
|
||||
|
||||
u_int32_t ndpi_quick_hash(unsigned char *str, u_int str_len);
|
||||
u_int64_t ndpi_quick_hash64(char *str, u_int str_len);
|
||||
u_int32_t ndpi_hash_string(char *str);
|
||||
u_int32_t ndpi_rev_hash_string(char *str);
|
||||
u_int32_t ndpi_hash_string_len(char *str, u_int len);
|
||||
u_int32_t ndpi_murmur_hash(char *str, u_int str_len);
|
||||
u_int32_t ndpi_quick_hash(const unsigned char *str, u_int str_len);
|
||||
u_int64_t ndpi_quick_hash64(const char *str, u_int str_len);
|
||||
u_int32_t ndpi_hash_string(const char *str);
|
||||
u_int32_t ndpi_rev_hash_string(const char *str);
|
||||
u_int32_t ndpi_hash_string_len(const char *str, u_int len);
|
||||
u_int32_t ndpi_murmur_hash(const char *str, u_int str_len);
|
||||
|
||||
/* ******************************* */
|
||||
|
||||
@@ -2100,13 +2100,13 @@ extern "C" {
|
||||
void ndpi_domain_classify_free(ndpi_domain_classify *s);
|
||||
u_int32_t ndpi_domain_classify_size(ndpi_domain_classify *s);
|
||||
bool ndpi_domain_classify_add(ndpi_domain_classify *s,
|
||||
u_int8_t class_id, char *domain);
|
||||
u_int8_t class_id, const char *domain);
|
||||
u_int32_t ndpi_domain_classify_add_domains(ndpi_domain_classify *s,
|
||||
u_int8_t class_id,
|
||||
char *file_path);
|
||||
bool ndpi_domain_classify_contains(ndpi_domain_classify *s,
|
||||
u_int8_t *class_id /* out */,
|
||||
char *domain);
|
||||
const char *domain);
|
||||
|
||||
/* ******************************* */
|
||||
|
||||
|
||||
+14
-3
@@ -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));
|
||||
}
|
||||
|
||||
@@ -68,6 +68,9 @@ void ndpi_domain_classify_free(ndpi_domain_classify *s) {
|
||||
u_int32_t ndpi_domain_classify_size(ndpi_domain_classify *s) {
|
||||
u_int32_t i, tot_len = sizeof(ndpi_domain_classify);
|
||||
|
||||
if(!s)
|
||||
return(0);
|
||||
|
||||
for(i=0; i<MAX_NUM_NDPI_DOMAIN_CLASSIFICATIONS; i++) {
|
||||
if(s->classes[i].domains != NULL) {
|
||||
tot_len += ndpi_bitmap64_size(s->classes[i].domains);
|
||||
@@ -82,9 +85,14 @@ u_int32_t ndpi_domain_classify_size(ndpi_domain_classify *s) {
|
||||
|
||||
bool ndpi_domain_classify_add(ndpi_domain_classify *s,
|
||||
u_int8_t class_id,
|
||||
char *domain) {
|
||||
const char *domain) {
|
||||
u_int32_t i;
|
||||
char *dot = strrchr(domain, '.');
|
||||
char *dot;
|
||||
|
||||
if(!s || !domain)
|
||||
return(false);
|
||||
|
||||
dot = strrchr(domain, '.');
|
||||
|
||||
if(!dot) return(false);
|
||||
if((!strcmp(dot, ".arpa")) || (!strcmp(dot, ".local")))
|
||||
@@ -184,11 +192,11 @@ static bool is_valid_domain_char(u_char c) {
|
||||
|
||||
bool ndpi_domain_classify_contains(ndpi_domain_classify *s,
|
||||
u_int8_t *class_id /* out */,
|
||||
char *domain) {
|
||||
const char *domain) {
|
||||
u_int32_t i, len;
|
||||
char *dot, *elem;
|
||||
const char *dot, *elem;
|
||||
|
||||
if(!domain) return(false);
|
||||
if(!domain || !s) return(false);
|
||||
if((len = strlen(domain)) == 0) return(false);
|
||||
if((dot = strrchr(domain, '.')) == NULL) return(false);
|
||||
if((!strcmp(dot, ".arpa")) || (!strcmp(dot, ".local"))) return(false);
|
||||
|
||||
+6
-6
@@ -30,14 +30,14 @@
|
||||
/* ******************************************************************** */
|
||||
|
||||
/* Based on djb2 hash - http://www.cse.yorku.ca/~oz/hash.html */
|
||||
u_int32_t ndpi_murmur_hash(char *str, u_int str_len) {
|
||||
u_int32_t ndpi_murmur_hash(const char *str, u_int str_len) {
|
||||
return(MurmurHash((void*)str, str_len, 0x87654321));
|
||||
}
|
||||
|
||||
/* ******************************************************************** */
|
||||
|
||||
/* Based on djb2 hash - http://www.cse.yorku.ca/~oz/hash.html */
|
||||
u_int32_t ndpi_quick_hash(unsigned char *str, u_int str_len) {
|
||||
u_int32_t ndpi_quick_hash(const unsigned char *str, u_int str_len) {
|
||||
u_int32_t hash = 5381, i;
|
||||
|
||||
for(i=0; i<str_len; i++)
|
||||
@@ -49,7 +49,7 @@ u_int32_t ndpi_quick_hash(unsigned char *str, u_int str_len) {
|
||||
/* ******************************************************************** */
|
||||
|
||||
/* Based on Daniel Lemire code */
|
||||
u_int64_t ndpi_quick_hash64(char *str, u_int str_len) {
|
||||
u_int64_t ndpi_quick_hash64(const char *str, u_int str_len) {
|
||||
u_int64_t h = 0;
|
||||
u_int i;
|
||||
|
||||
@@ -68,7 +68,7 @@ u_int64_t ndpi_quick_hash64(char *str, u_int str_len) {
|
||||
|
||||
See also http://burtleburtle.net/bob/hash/spooky.html
|
||||
*/
|
||||
u_int32_t ndpi_hash_string(char *str) {
|
||||
u_int32_t ndpi_hash_string(const char *str) {
|
||||
u_int32_t hash, i;
|
||||
|
||||
for(hash = i = 0; str[i] != '\0'; ++i) {
|
||||
@@ -86,7 +86,7 @@ u_int32_t ndpi_hash_string(char *str) {
|
||||
|
||||
/* ******************************************************************** */
|
||||
|
||||
u_int32_t ndpi_rev_hash_string(char *str) {
|
||||
u_int32_t ndpi_rev_hash_string(const char *str) {
|
||||
u_int32_t hash, i;
|
||||
int len = strlen(str);
|
||||
|
||||
@@ -109,7 +109,7 @@ u_int32_t ndpi_rev_hash_string(char *str) {
|
||||
/* ******************************************************************** */
|
||||
|
||||
/* Same as above but with strings with lenght */
|
||||
u_int32_t ndpi_hash_string_len(char *str, u_int len) {
|
||||
u_int32_t ndpi_hash_string_len(const char *str, u_int len) {
|
||||
u_int32_t hash, i;
|
||||
|
||||
for(hash = i = 0; i< len; ++i) {
|
||||
|
||||
Reference in New Issue
Block a user