Coverage Report

Created: 2026-10-08 07:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ndpi/fuzz/fuzz_tls_certificate.c
Line
Count
Source
1
#include "ndpi_api.h"
2
#include "ndpi_private.h"
3
#include "fuzz_common_code.h"
4
5
#include <stdint.h>
6
#include <stdio.h>
7
8
struct ndpi_tcphdr tcph;
9
struct ndpi_iphdr iph;
10
struct ndpi_ipv6hdr iphv6;
11
12
struct ndpi_detection_module_struct *ndpi_struct = NULL;
13
struct ndpi_flow_struct *ndpi_flow = NULL;
14
15
static char *path = NULL;
16
17
44
int LLVMFuzzerInitialize(int *argc, char ***argv) {
18
44
  (void)argc;
19
20
44
  path = dirname(strdup(*argv[0])); /* No errors; no free! */
21
44
  return 0;
22
44
}
23
24
1.99k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
25
1.99k
  struct ndpi_packet_struct *packet;
26
1.99k
  int is_ipv6;
27
28
1.99k
  if (ndpi_struct == NULL) {
29
1
    fuzz_init_detection_module(&ndpi_struct, NULL, path);
30
1
    ndpi_flow = ndpi_calloc(1, sizeof(struct ndpi_flow_struct));
31
1
  }
32
33
1.99k
  if(size == 0)
34
0
    return -1;
35
36
1.99k
  fuzz_set_alloc_callbacks_and_seed(size);
37
38
1.99k
  packet = &ndpi_struct->packet;
39
1.99k
  packet->payload = data;
40
1.99k
  packet->payload_packet_len = size;
41
1.99k
  is_ipv6 = data[size - 1] % 5 ? 1 : 0; /* "Random" ipv4 vs ipv6 */
42
1.99k
  packet->iphv6 = is_ipv6 ? &iphv6 : NULL;
43
1.99k
  packet->iph = is_ipv6 ? NULL : &iph;
44
1.99k
  packet->tcp = &tcph;
45
46
1.99k
  memset(ndpi_flow, 0, sizeof(struct ndpi_flow_struct));
47
1.99k
  ndpi_hostname_sni_set(ndpi_flow, (const u_int8_t *)"doh.opendns.com",
48
1.99k
                        strlen("doh.opendns.com"), NDPI_HOSTNAME_NORM_ALL);
49
1.99k
  ndpi_flow->core.detected_protocol_stack[0] = NDPI_PROTOCOL_TLS;
50
51
1.99k
  processCertificateElements(ndpi_struct, ndpi_flow, 0, size);
52
1.99k
  ndpi_free_flow_data(ndpi_flow);
53
54
1.99k
  return 0;
55
1.99k
}