Coverage Report

Created: 2025-07-18 07:07

/src/ndpi/fuzz/fuzz_filecfg_malicious_sha1.c
Line
Count
Source
1
#include "ndpi_api.h"
2
#include "ndpi_private.h"
3
#include "fuzz_common_code.h"
4
5
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
6
void ndpi_debug_printf(uint16_t proto, struct ndpi_detection_module_struct *ndpi_str, ndpi_log_level_t log_level,
7
                       const char *file_name, const char *func_name, unsigned int line_number, const char *format, ...);
8
#endif
9
10
436
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
11
436
  struct ndpi_detection_module_struct *ndpi_struct;
12
436
  FILE *fd;
13
14
  /* To allow memory allocation failures */
15
436
  fuzz_set_alloc_callbacks_and_seed(size);
16
17
  /* We don't need a complete (and costly to set up) context!
18
     Setting up manually only what is really needed is complex (and error prone!)
19
     but allow us to be significant faster and to have better coverage */
20
21
  /* TODO: if it works, we can extend the same logic to other fuzzers */
22
23
436
  ndpi_struct = ndpi_calloc(1, sizeof(struct ndpi_detection_module_struct));
24
25
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
26
  set_ndpi_debug_function(ndpi_struct, (ndpi_debug_function_ptr)ndpi_debug_printf);
27
#endif
28
436
  if(ndpi_struct)
29
435
    ndpi_struct->cfg.log_level = NDPI_LOG_DEBUG_EXTRA;
30
31
436
  fd = buffer_to_file(data, size);
32
436
  load_malicious_sha1_file_fd(ndpi_struct, fd);
33
436
  if(fd)
34
436
    fclose(fd);
35
36
  /* We also need to manually free anything! */
37
436
  if(ndpi_struct && ndpi_struct->malicious_sha1_hashmap)
38
351
    ndpi_hash_free(&ndpi_struct->malicious_sha1_hashmap);
39
436
  ndpi_free(ndpi_struct);
40
41
436
  return 0;
42
436
}