Coverage Report

Created: 2026-01-05 06:49

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