fuzz: extend fuzzing coverage (#2281)
This commit is contained in:
+54
-10
@@ -20,10 +20,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
u_int16_t i, num_iteration, ip_len;
|
||||
ndpi_patricia_tree_t *p, *p_cloned;
|
||||
u_int16_t maxbits;
|
||||
int is_ipv6, is_added = 0;
|
||||
int is_added = 0;
|
||||
ndpi_prefix_t prefix, prefix_added;
|
||||
u_char *ip;
|
||||
ndpi_patricia_node_t *node;
|
||||
int tree_type; /* 0: ipv4, 1: ipv6, 2: mac */
|
||||
|
||||
/* Just to have some data */
|
||||
if (fuzzed_data.remaining_bytes() < 1024)
|
||||
@@ -32,11 +33,13 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
/* To allow memory allocation failures */
|
||||
fuzz_set_alloc_callbacks_and_seed(size);
|
||||
|
||||
is_ipv6 = fuzzed_data.ConsumeBool();
|
||||
if (is_ipv6)
|
||||
tree_type = fuzzed_data.ConsumeIntegralInRange(0, 2);
|
||||
if (tree_type == 0)
|
||||
maxbits = 32;
|
||||
else if (tree_type == 1)
|
||||
maxbits = 128;
|
||||
else
|
||||
maxbits = 32;
|
||||
maxbits = 48;
|
||||
|
||||
p = ndpi_patricia_new(maxbits);
|
||||
|
||||
@@ -47,7 +50,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
/* "Random" add */
|
||||
num_iteration = fuzzed_data.ConsumeIntegral<u_int8_t>();
|
||||
for (i = 0; i < num_iteration; i++) {
|
||||
if (!is_ipv6) {
|
||||
if (tree_type == 0) {
|
||||
if(fuzzed_data.remaining_bytes() > 4) {
|
||||
std::vector<u_int8_t>data = fuzzed_data.ConsumeBytes<u_int8_t>(4);
|
||||
ip = data.data();
|
||||
@@ -67,7 +70,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
assert(ndpi_patricia_get_node_u64(node) == 0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else if (tree_type == 1){
|
||||
if(fuzzed_data.remaining_bytes() > 16) {
|
||||
std::vector<u_int8_t>data = fuzzed_data.ConsumeBytes<u_int8_t>(16);
|
||||
ip = data.data();
|
||||
@@ -87,6 +90,26 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
assert(ndpi_patricia_get_node_u64(node) == 0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(fuzzed_data.remaining_bytes() > 6) {
|
||||
std::vector<u_int8_t>data = fuzzed_data.ConsumeBytes<u_int8_t>(6);
|
||||
ip = data.data();
|
||||
ip_len = fuzzed_data.ConsumeIntegralInRange(0, 49); /* 49 to force error */
|
||||
ndpi_fill_prefix_mac(&prefix, ip, ip_len, 48);
|
||||
node = ndpi_patricia_lookup(p, &prefix);
|
||||
/* Keep one random node really added */
|
||||
if (node && is_added == 0 && fuzzed_data.ConsumeBool()) {
|
||||
is_added = 1;
|
||||
prefix_added = prefix;
|
||||
/* Some random operations on this node */
|
||||
ndpi_patricia_get_node_prefix(node);
|
||||
ndpi_patricia_get_node_bits(node);
|
||||
ndpi_patricia_set_node_data(node, NULL);
|
||||
assert(ndpi_patricia_get_node_data(node) == NULL);
|
||||
ndpi_patricia_set_node_u64(node, 0);
|
||||
assert(ndpi_patricia_get_node_u64(node) == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +119,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
/* "Random" exact search. Remove if found */
|
||||
num_iteration = fuzzed_data.ConsumeIntegral<u_int8_t>();
|
||||
for (i = 0; i < num_iteration; i++) {
|
||||
if (!is_ipv6) {
|
||||
if (tree_type == 0) {
|
||||
if(fuzzed_data.remaining_bytes() > 4) {
|
||||
std::vector<u_int8_t>data = fuzzed_data.ConsumeBytes<u_int8_t>(4);
|
||||
ip = data.data();
|
||||
@@ -106,7 +129,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
if (node)
|
||||
ndpi_patricia_remove(p, node);
|
||||
}
|
||||
} else {
|
||||
} else if (tree_type == 1) {
|
||||
if(fuzzed_data.remaining_bytes() > 16) {
|
||||
std::vector<u_int8_t>data = fuzzed_data.ConsumeBytes<u_int8_t>(16);
|
||||
ip = data.data();
|
||||
@@ -116,7 +139,18 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
if (node)
|
||||
ndpi_patricia_remove(p, node);
|
||||
}
|
||||
} else {
|
||||
if(fuzzed_data.remaining_bytes() > 6) {
|
||||
std::vector<u_int8_t>data = fuzzed_data.ConsumeBytes<u_int8_t>(6);
|
||||
ip = data.data();
|
||||
ip_len = fuzzed_data.ConsumeIntegralInRange(0, 48);
|
||||
ndpi_fill_prefix_mac(&prefix, ip, ip_len, 48);
|
||||
node = ndpi_patricia_search_exact(p, &prefix);
|
||||
if (node)
|
||||
ndpi_patricia_remove(p, node);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* Exact search of an added node */
|
||||
if (is_added)
|
||||
@@ -125,7 +159,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
/* "Random" best search. Remove if found */
|
||||
num_iteration = fuzzed_data.ConsumeIntegral<u_int8_t>();
|
||||
for (i = 0; i < num_iteration; i++) {
|
||||
if (!is_ipv6) {
|
||||
if (tree_type == 0) {
|
||||
if(fuzzed_data.remaining_bytes() > 4) {
|
||||
std::vector<u_int8_t>data = fuzzed_data.ConsumeBytes<u_int8_t>(4);
|
||||
ip = data.data();
|
||||
@@ -135,7 +169,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
if (node)
|
||||
ndpi_patricia_remove(p, node);
|
||||
}
|
||||
} else {
|
||||
} else if (tree_type == 1) {
|
||||
if(fuzzed_data.remaining_bytes() > 16) {
|
||||
std::vector<u_int8_t>data = fuzzed_data.ConsumeBytes<u_int8_t>(16);
|
||||
ip = data.data();
|
||||
@@ -145,6 +179,16 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
if (node)
|
||||
ndpi_patricia_remove(p, node);
|
||||
}
|
||||
} else {
|
||||
if(fuzzed_data.remaining_bytes() > 6) {
|
||||
std::vector<u_int8_t>data = fuzzed_data.ConsumeBytes<u_int8_t>(6);
|
||||
ip = data.data();
|
||||
ip_len = fuzzed_data.ConsumeIntegralInRange(0, 48);
|
||||
ndpi_fill_prefix_mac(&prefix, ip, ip_len, 48);
|
||||
node = ndpi_patricia_search_best(p, &prefix);
|
||||
if (node)
|
||||
ndpi_patricia_remove(p, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Best search of an added node */
|
||||
|
||||
Reference in New Issue
Block a user