/src/ndpi/fuzz/fuzz_tls_certificate.c
Line | Count | Source (jump to first uncovered line) |
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 | 2.18k | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
16 | 2.18k | struct ndpi_packet_struct *packet; |
17 | 2.18k | int is_ipv6; |
18 | | |
19 | 2.18k | if (ndpi_struct == NULL) { |
20 | 1 | fuzz_init_detection_module(&ndpi_struct, NULL); |
21 | 1 | ndpi_flow = ndpi_calloc(1, sizeof(struct ndpi_flow_struct)); |
22 | 1 | } |
23 | | |
24 | 2.18k | if(size == 0) |
25 | 0 | return -1; |
26 | | |
27 | 2.18k | packet = &ndpi_struct->packet; |
28 | 2.18k | packet->payload = data; |
29 | 2.18k | packet->payload_packet_len = size; |
30 | 2.18k | is_ipv6 = data[size - 1] % 5 ? 1 : 0; /* "Random" ipv4 vs ipv6 */ |
31 | 2.18k | packet->iphv6 = is_ipv6 ? &iphv6 : NULL; |
32 | 2.18k | packet->iph = is_ipv6 ? NULL : &iph; |
33 | 2.18k | packet->tcp = &tcph; |
34 | | |
35 | 2.18k | memset(ndpi_flow, 0, sizeof(struct ndpi_flow_struct)); |
36 | 2.18k | strcpy(ndpi_flow->host_server_name, "doh.opendns.com"); |
37 | 2.18k | ndpi_flow->detected_protocol_stack[0] = NDPI_PROTOCOL_TLS; |
38 | | |
39 | 2.18k | processCertificateElements(ndpi_struct, ndpi_flow, 0, size); |
40 | 2.18k | ndpi_free_flow_data(ndpi_flow); |
41 | | |
42 | 2.18k | return 0; |
43 | 2.18k | } |