Coverage Report

Created: 2025-08-03 06:32

/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
437
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
11
437
  struct ndpi_detection_module_struct *ndpi_struct;
12
437
  FILE *fd;
13
14
  /* To allow memory allocation failures */
15
437
  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
437
  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
437
  if(ndpi_struct)
29
436
    ndpi_struct->cfg.log_level = NDPI_LOG_DEBUG_EXTRA;
30
31
437
  fd = buffer_to_file(data, size);
32
437
  load_malicious_sha1_file_fd(ndpi_struct, fd);
33
437
  if(fd)
34
437
    fclose(fd);
35
36
  /* We also need to manually free anything! */
37
437
  if(ndpi_struct && ndpi_struct->malicious_sha1_hashmap)
38
353
    ndpi_hash_free(&ndpi_struct->malicious_sha1_hashmap);
39
437
  ndpi_free(ndpi_struct);
40
41
437
  return 0;
42
437
}