Coverage Report

Created: 2026-06-25 07:00

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