Coverage Report

Created: 2026-10-08 07:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ndpi/fuzz/fuzz_is_stun.c
Line
Count
Source
1
#include "ndpi_api.h"
2
#include "ndpi_private.h"
3
#include "fuzz_common_code.h"
4
5
#include <arpa/inet.h>
6
7
static struct ndpi_detection_module_struct *ndpi_struct = NULL;
8
static struct ndpi_flow_struct ndpi_flow;
9
struct ndpi_iphdr iph;
10
#ifdef STUN_TCP
11
struct ndpi_tcphdr tcph;
12
#else
13
struct ndpi_udphdr udph;
14
#endif
15
16
static char *path = NULL;
17
18
44
int LLVMFuzzerInitialize(int *argc, char ***argv) {
19
44
  (void)argc;
20
21
44
  path = dirname(strdup(*argv[0])); /* No errors; no free! */
22
44
  return 0;
23
44
}
24
25
46.0k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
26
46.0k
  u_int16_t app_proto; /* unused */
27
46.0k
  struct ndpi_packet_struct *packet;
28
46.0k
  ndpi_protocol_category_t category;
29
30
46.0k
  if (ndpi_struct == NULL) {
31
5
    fuzz_init_detection_module(&ndpi_struct, NULL, path);
32
33
    /* Initialize IP/transport headers once — they are never modified */
34
5
    memset(&iph, 0, sizeof(iph));
35
5
    iph.version = 4;
36
5
    iph.ihl = 5;
37
#ifdef STUN_TCP
38
    iph.protocol = 6; /* TCP */
39
#else
40
5
    iph.protocol = 17; /* UDP */
41
5
#endif
42
5
    iph.saddr = htonl(0x0A000001); /* 10.0.0.1 */
43
5
    iph.daddr = htonl(0x0A000002); /* 10.0.0.2 */
44
45
#ifdef STUN_TCP
46
    memset(&tcph, 0, sizeof(tcph));
47
    tcph.source = htons(3478);
48
    tcph.dest = htons(3478);
49
#else
50
5
    memset(&udph, 0, sizeof(udph));
51
5
    udph.source = htons(3478);
52
5
    udph.dest = htons(3478);
53
5
#endif
54
5
  }
55
56
  /* Reset flow state to avoid stale data from previous calls */
57
46.0k
  memset(&ndpi_flow, 0, sizeof(ndpi_flow));
58
59
46.0k
  packet = &ndpi_struct->packet;
60
46.0k
  packet->payload = data;
61
46.0k
  packet->payload_packet_len = size;
62
46.0k
#ifndef STUN_TCP
63
46.0k
  packet->udp = &udph;
64
#else
65
  packet->tcp = &tcph;
66
#endif
67
46.0k
  packet->iph = &iph; /* IPv4 only */
68
69
46.0k
  is_stun(ndpi_struct, &ndpi_flow, &app_proto, &category);
70
71
46.0k
  ndpi_free_flow_data(&ndpi_flow);
72
73
46.0k
  return 0;
74
46.0k
}