aboutsummaryrefslogtreecommitdiff
path: root/fuzz/fuzz_ds_domain_classify.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fuzz/fuzz_ds_domain_classify.cpp')
-rw-r--r--fuzz/fuzz_ds_domain_classify.cpp24
1 files changed, 22 insertions, 2 deletions
diff --git a/fuzz/fuzz_ds_domain_classify.cpp b/fuzz/fuzz_ds_domain_classify.cpp
index 5e068a9fe..ccb106a6f 100644
--- a/fuzz/fuzz_ds_domain_classify.cpp
+++ b/fuzz/fuzz_ds_domain_classify.cpp
@@ -1,4 +1,5 @@
#include "ndpi_api.h"
+#include "ndpi_private.h"
#include "fuzz_common_code.h"
#include <stdint.h>
@@ -8,7 +9,14 @@
static struct ndpi_detection_module_struct *ndpi_struct = NULL;
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+extern "C" {
+
+#ifdef NDPI_ENABLE_DEBUG_MESSAGES
+void ndpi_debug_printf(unsigned int proto, struct ndpi_detection_module_struct *ndpi_str, ndpi_log_level_t log_level,
+ const char *file_name, const char *func_name, unsigned int line_number, const char *format, ...);
+#endif
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
FuzzedDataProvider fuzzed_data(data, size);
u_int16_t i, num_iteration, is_added = 0;
bool rc;
@@ -16,8 +24,18 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
u_int16_t class_id;
std::string value, value_added;
+ /* We don't need a complete (and costly to set up) context!
+ Setting up manually only what is really needed is complex (and error prone!)
+ but allow us to be significant faster and to have better coverage */
if (ndpi_struct == NULL) {
- fuzz_init_detection_module(&ndpi_struct, NULL);
+ ndpi_struct = (struct ndpi_detection_module_struct *)ndpi_calloc(1, sizeof(struct ndpi_detection_module_struct));
+#ifdef NDPI_ENABLE_DEBUG_MESSAGES
+ set_ndpi_debug_function(ndpi_struct, (ndpi_debug_function_ptr)ndpi_debug_printf);
+#endif
+ if (ndpi_struct) {
+ ndpi_struct->cfg.log_level = NDPI_LOG_DEBUG_EXTRA;
+ ndpi_load_domain_suffixes(ndpi_struct, (char *)"public_suffix_list.dat");
+ }
}
/* To allow memory allocation failures */
@@ -61,3 +79,5 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
return 0;
}
+
+}