fuzz: add fuzzer testing nDPI (initial) configurations (#1830)
The goal of this fuzzer is to test init and deinit of the library, with different configurations. In details: * random memory allocation failures, even during init phase * random `ndpi_init_prefs` parameter of `ndpi_init_detection_module()` * random LRU caches sizes * random bitmask of enabled protocols * random parameters of `ndpi_set_detection_preferences()` * random initialization of opportunistic TLS * random load/don't load of configuration files This new fuzzer is a C++ file, because it uses `FuzzedDataProvider` class (see https://github.com/google/fuzzing/blob/master/docs/split-inputs.md). Note that the (existing) fuzzers need to be linked with C++ compiler anyway, so this new fuzzer doesn't add any new requirements.
This commit is contained in:
+13
-2
@@ -223,10 +223,15 @@ void ac_automata_enable_debug (int debug) {
|
||||
AC_ERROR_t ac_automata_add (AC_AUTOMATA_t * thiz, AC_PATTERN_t * patt)
|
||||
{
|
||||
unsigned int i;
|
||||
AC_NODE_t * n = thiz->root;
|
||||
AC_NODE_t * n;
|
||||
AC_NODE_t * next;
|
||||
AC_ALPHABET_t alpha;
|
||||
|
||||
if(!thiz || !patt || !patt->astring)
|
||||
return ACERR_ERROR;
|
||||
|
||||
n = thiz->root;
|
||||
|
||||
if(!thiz->automata_open)
|
||||
return ACERR_AUTOMATA_CLOSED;
|
||||
|
||||
@@ -556,6 +561,9 @@ static AC_ERROR_t ac_automata_release_node(AC_AUTOMATA_t * thiz,
|
||||
}
|
||||
void ac_automata_release (AC_AUTOMATA_t * thiz, uint8_t free_pattern) {
|
||||
|
||||
if(!thiz)
|
||||
return;
|
||||
|
||||
ac_automata_walk(thiz,ac_automata_release_node,NULL,free_pattern ? (void *)1:NULL);
|
||||
|
||||
if(free_pattern <= 1) {
|
||||
@@ -1013,8 +1021,11 @@ static int node_register_matchstr (AC_NODE_t * thiz, AC_PATTERN_t * str,int is_e
|
||||
if (thiz->matched_patterns && node_has_matchstr(thiz, str))
|
||||
return 0;
|
||||
|
||||
if(!thiz->matched_patterns)
|
||||
if(!thiz->matched_patterns) {
|
||||
thiz->matched_patterns = node_resize_mp(thiz->matched_patterns);
|
||||
if(!thiz->matched_patterns)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Manage memory */
|
||||
if (thiz->matched_patterns->num >= thiz->matched_patterns->max) {
|
||||
|
||||
+29
-3
@@ -218,6 +218,8 @@ static ndpi_prefix_t * ndpi_New_Prefix2 (int family, void *dest, int bitlen, ndp
|
||||
default_bitlen = sizeof(struct in6_addr) * 8;
|
||||
if(prefix == NULL) {
|
||||
prefix = (ndpi_prefix_t*)ndpi_calloc(1, sizeof (ndpi_prefix_t));
|
||||
if(!prefix)
|
||||
return (NULL);
|
||||
dynamic_allocated++;
|
||||
}
|
||||
memcpy (&prefix->add.sin6, dest, sizeof(struct in6_addr));
|
||||
@@ -232,7 +234,9 @@ static ndpi_prefix_t * ndpi_New_Prefix2 (int family, void *dest, int bitlen, ndp
|
||||
//prefix4_t size incorrect on NT
|
||||
prefix = ndpi_calloc(1, sizeof (ndpi_prefix_t));
|
||||
#endif /* NT */
|
||||
|
||||
if(!prefix)
|
||||
return (NULL);
|
||||
|
||||
dynamic_allocated++;
|
||||
}
|
||||
memcpy (&prefix->add.sin, dest, sizeof(struct in_addr));
|
||||
@@ -298,6 +302,8 @@ ndpi_patricia_tree_t *
|
||||
ndpi_patricia_new (u_int16_t maxbits)
|
||||
{
|
||||
ndpi_patricia_tree_t *patricia = (ndpi_patricia_tree_t*)ndpi_calloc(1, sizeof *patricia);
|
||||
if(!patricia)
|
||||
return (NULL);
|
||||
|
||||
patricia->maxbits = maxbits;
|
||||
patricia->head = NULL;
|
||||
@@ -536,7 +542,9 @@ ndpi_patricia_search_best2 (ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefi
|
||||
u_int16_t bitlen;
|
||||
int cnt = 0;
|
||||
|
||||
assert (patricia);
|
||||
if(patricia == NULL)
|
||||
return (NULL);
|
||||
|
||||
assert (prefix);
|
||||
assert (prefix->bitlen <= patricia->maxbits);
|
||||
|
||||
@@ -653,8 +661,14 @@ ndpi_patricia_lookup (ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefix)
|
||||
|
||||
if(patricia->head == NULL) {
|
||||
node = (ndpi_patricia_node_t*)ndpi_calloc(1, sizeof *node);
|
||||
if(!node)
|
||||
return NULL;
|
||||
node->bit = prefix->bitlen;
|
||||
node->prefix = ndpi_Ref_Prefix (prefix);
|
||||
if(!node->prefix) {
|
||||
ndpi_free(node);
|
||||
return NULL;
|
||||
}
|
||||
node->parent = NULL;
|
||||
node->l = node->r = NULL;
|
||||
node->data = NULL;
|
||||
@@ -757,6 +771,9 @@ ndpi_patricia_lookup (ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefix)
|
||||
return (node);
|
||||
}
|
||||
node->prefix = ndpi_Ref_Prefix (prefix);
|
||||
if(!node->prefix) {
|
||||
return NULL;
|
||||
}
|
||||
#ifdef PATRICIA_DEBUG
|
||||
fprintf (stderr, "patricia_lookup: new node #1 %s/%d (glue mod)\n",
|
||||
ndpi_prefix_toa (prefix), prefix->bitlen);
|
||||
@@ -769,6 +786,10 @@ ndpi_patricia_lookup (ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefix)
|
||||
if(!new_node) return NULL;
|
||||
new_node->bit = prefix->bitlen;
|
||||
new_node->prefix = ndpi_Ref_Prefix (prefix);
|
||||
if(!new_node->prefix) {
|
||||
ndpi_free(new_node);
|
||||
return NULL;
|
||||
}
|
||||
new_node->parent = NULL;
|
||||
new_node->l = new_node->r = NULL;
|
||||
new_node->data = NULL;
|
||||
@@ -820,7 +841,12 @@ ndpi_patricia_lookup (ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefix)
|
||||
else {
|
||||
glue = (ndpi_patricia_node_t*)ndpi_calloc(1, sizeof *glue);
|
||||
|
||||
if(!glue) return(NULL);
|
||||
if(!glue) {
|
||||
ndpi_Deref_Prefix(new_node->prefix);
|
||||
ndpi_DeleteEntry (new_node);
|
||||
patricia->num_active_node--;
|
||||
return(NULL);
|
||||
}
|
||||
glue->bit = differ_bit;
|
||||
glue->prefix = NULL;
|
||||
glue->parent = node->parent;
|
||||
|
||||
Reference in New Issue
Block a user