aboutsummaryrefslogtreecommitdiff
path: root/fuzz
diff options
context:
space:
mode:
authorIvan Nardi <12729895+IvanNardi@users.noreply.github.com>2025-06-09 09:00:17 +0200
committerGitHub <noreply@github.com>2025-06-09 09:00:17 +0200
commitcbd7136b3480774a10f18744d33d3694ffee221b (patch)
treea9981734e85c500ab4605e913cd6ee8b8197492d /fuzz
parent75395cb264f9bfd38d27ac0ba506acc9eab22e34 (diff)
Remove `NDPI_PROTOCOL_BITMASK`; add a new generic bitmask data structure (#2871)
The main difference is that the memory is allocated at runtime Typical usercase: ``` struct ndpi_bitmask b; ndpi_bitmask_alloc(&b, ndpi_get_num_internal_protocols()); ndpi_bitmask_set(&b, $BIT); ndpi_bitmask_is_set(&b, $BIT); [...] ndpi_bitmask_dealloc(&b); ``` See #2136
Diffstat (limited to 'fuzz')
-rw-r--r--fuzz/fuzz_config.cpp22
-rw-r--r--fuzz/fuzz_readerutils_parseprotolist.cpp11
2 files changed, 21 insertions, 12 deletions
diff --git a/fuzz/fuzz_config.cpp b/fuzz/fuzz_config.cpp
index ce8f74c80..52ce1ccfe 100644
--- a/fuzz/fuzz_config.cpp
+++ b/fuzz/fuzz_config.cpp
@@ -15,7 +15,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
u_int8_t protocol_was_guessed, unused;
u_int32_t i, ret;
u_int16_t bool_value;
- NDPI_INTERNAL_PROTOCOL_BITMASK enabled_bitmask;
+ struct ndpi_bitmask enabled_bitmask;
struct ndpi_lru_cache_stats lru_stats;
struct ndpi_patricia_tree_stats patricia_stats;
struct ndpi_automa_stats automa_stats;
@@ -46,17 +46,21 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
else
g_ctx = NULL;
- NDPI_INTERNAL_PROTOCOL_SET_ALL(enabled_bitmask);
- if(fuzzed_data.ConsumeBool()) {
- NDPI_INTERNAL_PROTOCOL_RESET(enabled_bitmask);
- for(i = 0; i < ndpi_get_num_internal_protocols(); i++) {
- if(fuzzed_data.ConsumeBool())
- NDPI_INTERNAL_PROTOCOL_ADD(enabled_bitmask, i);
+ if(ndpi_bitmask_alloc(&enabled_bitmask, ndpi_get_num_internal_protocols()) == 0) {
+ ndpi_bitmask_set_all(&enabled_bitmask);
+ if(fuzzed_data.ConsumeBool()) {
+ ndpi_bitmask_reset(&enabled_bitmask);
+ for(i = 0; i < ndpi_get_num_internal_protocols(); i++) {
+ if(fuzzed_data.ConsumeBool())
+ ndpi_bitmask_set(&enabled_bitmask, i);
+ }
}
+ ndpi_info_mod = ndpi_init_detection_module_ext(g_ctx, &enabled_bitmask);
+ ndpi_bitmask_dealloc(&enabled_bitmask);
+ } else {
+ ndpi_info_mod = ndpi_init_detection_module_ext(g_ctx, NULL);
}
- ndpi_info_mod = ndpi_init_detection_module_ext(g_ctx, &enabled_bitmask);
-
set_ndpi_debug_function(ndpi_info_mod, NULL);
ndpi_set_user_data(ndpi_info_mod, (void *)0xabcdabcd); /* Random pointer */
diff --git a/fuzz/fuzz_readerutils_parseprotolist.cpp b/fuzz/fuzz_readerutils_parseprotolist.cpp
index 3d004f74e..3dfcdd0f3 100644
--- a/fuzz/fuzz_readerutils_parseprotolist.cpp
+++ b/fuzz/fuzz_readerutils_parseprotolist.cpp
@@ -19,17 +19,19 @@ int monitoring_enabled = 0;
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
FuzzedDataProvider fuzzed_data(data, size);
int inverted_logic;
- NDPI_INTERNAL_PROTOCOL_BITMASK bitmask;
+ struct ndpi_bitmask bitmask;
char *str;
+ ndpi_bitmask_alloc(&bitmask, ndpi_get_num_internal_protocols()); /* Don't make this call to fail...*/
+
/* To allow memory allocation failures */
fuzz_set_alloc_callbacks_and_seed(size);
inverted_logic = size % 2; /* pseudo-random */
if(inverted_logic) {
- NDPI_INTERNAL_PROTOCOL_SET_ALL(bitmask);
+ ndpi_bitmask_set_all(&bitmask);
} else {
- NDPI_INTERNAL_PROTOCOL_RESET(bitmask);
+ ndpi_bitmask_reset(&bitmask);
}
str = (char *)ndpi_malloc(size + 1); /* We need a null-terminated string */
@@ -41,5 +43,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
ndpi_free(str);
}
+
+ ndpi_bitmask_dealloc(&bitmask);
+
return 0;
}