fuzz: fix memory allocation failure logic (#1867)
We *do* want to have some allocation errors.
Fix some related bugs
Fix: 29be01ef
This commit is contained in:
+6
-2
@@ -259,7 +259,7 @@ AC_ERROR_t ac_automata_add (AC_AUTOMATA_t * thiz, AC_PATTERN_t * patt)
|
||||
if(thiz->max_str_len < patt->length)
|
||||
thiz->max_str_len = patt->length;
|
||||
|
||||
if(n->final) {
|
||||
if(n->final && n->matched_patterns) {
|
||||
patt->rep.number = n->matched_patterns->patterns[0].rep.number;
|
||||
return ACERR_DUPLICATE_PATTERN;
|
||||
}
|
||||
@@ -372,7 +372,7 @@ static AC_ERROR_t ac_finalize_node(AC_AUTOMATA_t * thiz,AC_NODE_t * n, int idx,
|
||||
AC_ERROR_t ac_automata_finalize (AC_AUTOMATA_t * thiz) {
|
||||
|
||||
AC_ERROR_t r = ACERR_SUCCESS;
|
||||
if(!thiz->automata_open) return r;
|
||||
if(!thiz || !thiz->automata_open) return r;
|
||||
|
||||
ac_automata_traverse_setfailure (thiz);
|
||||
thiz->id=0;
|
||||
@@ -439,6 +439,8 @@ int ac_automata_search (AC_AUTOMATA_t * thiz,
|
||||
AC_NODE_t *next;
|
||||
AC_ALPHABET_t *apos;
|
||||
|
||||
if(!thiz || !txt) return -1;
|
||||
|
||||
thiz->stats.n_search++;
|
||||
|
||||
if(thiz->automata_open)
|
||||
@@ -688,6 +690,8 @@ static void dump_node_str(AC_AUTOMATA_t * thiz, AC_NODE_t * node,
|
||||
void ac_automata_dump(AC_AUTOMATA_t * thiz, FILE *file) {
|
||||
struct aho_dump_info ai;
|
||||
|
||||
if(!thiz) return;
|
||||
|
||||
memset((char *)&ai,0,sizeof(ai));
|
||||
ai.file = file ? file : stdout;
|
||||
fprintf(ai.file,"---DUMP- all nodes %u - max strlen %u -%s---\n",
|
||||
|
||||
+14
-5
@@ -321,7 +321,9 @@ ndpi_patricia_new (u_int16_t maxbits)
|
||||
void
|
||||
ndpi_Clear_Patricia (ndpi_patricia_tree_t *patricia, ndpi_void_fn_t func)
|
||||
{
|
||||
assert (patricia);
|
||||
if(!patricia)
|
||||
return;
|
||||
|
||||
if(patricia->head) {
|
||||
|
||||
ndpi_patricia_node_t *Xstack[PATRICIA_MAXBITS+1];
|
||||
@@ -377,6 +379,9 @@ void
|
||||
ndpi_patricia_process (ndpi_patricia_tree_t *patricia, ndpi_void_fn2_t func)
|
||||
{
|
||||
ndpi_patricia_node_t *node;
|
||||
|
||||
if (!patricia)
|
||||
return;
|
||||
assert (func);
|
||||
|
||||
PATRICIA_WALK (patricia->head, node) {
|
||||
@@ -451,7 +456,7 @@ ndpi_patricia_walk_inorder(ndpi_patricia_node_t *node, ndpi_void_fn3_t func, voi
|
||||
|
||||
size_t
|
||||
ndpi_patricia_walk_tree_inorder(ndpi_patricia_tree_t *patricia, ndpi_void_fn3_t func, void *data) {
|
||||
if (patricia->head == NULL)
|
||||
if (patricia == NULL || patricia->head == NULL)
|
||||
return 0;
|
||||
|
||||
return ndpi_patricia_walk_inorder(patricia->head, func, data);
|
||||
@@ -464,7 +469,8 @@ ndpi_patricia_search_exact (ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefi
|
||||
u_char *addr;
|
||||
u_int16_t bitlen;
|
||||
|
||||
assert (patricia);
|
||||
if (!patricia)
|
||||
return (NULL);
|
||||
assert (prefix);
|
||||
assert (prefix->bitlen <= patricia->maxbits);
|
||||
|
||||
@@ -650,12 +656,14 @@ ndpi_patricia_lookup (ndpi_patricia_tree_t *patricia, ndpi_prefix_t *prefix)
|
||||
u_int16_t bitlen, check_bit, differ_bit;
|
||||
int i, j;
|
||||
|
||||
if(!patricia)
|
||||
return (NULL);
|
||||
|
||||
#ifdef PATRICIA_DEBUG
|
||||
fprintf (stderr, "patricia_lookup() %s/%d (head)\n",
|
||||
ndpi_prefix_toa (prefix), prefix->bitlen);
|
||||
#endif /* PATRICIA_DEBUG */
|
||||
|
||||
assert (patricia);
|
||||
assert (prefix);
|
||||
assert (prefix->bitlen <= patricia->maxbits);
|
||||
|
||||
@@ -888,7 +896,8 @@ ndpi_patricia_remove (ndpi_patricia_tree_t *patricia, ndpi_patricia_node_t *node
|
||||
{
|
||||
ndpi_patricia_node_t *parent, *child;
|
||||
|
||||
assert (patricia);
|
||||
if(!patricia)
|
||||
return;
|
||||
assert (node);
|
||||
|
||||
if(node->r && node->l) {
|
||||
|
||||
Reference in New Issue
Block a user