/src/ndpi/fuzz/fuzz_quic_get_crypto_data.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_detection_module_struct *ndpi_info_mod = NULL; |
9 | | struct ndpi_flow_struct *flow = NULL; |
10 | | |
11 | | static char *path = NULL; |
12 | | |
13 | 44 | int LLVMFuzzerInitialize(int *argc, char ***argv) { |
14 | 44 | (void)argc; |
15 | | |
16 | 44 | path = dirname(strdup(*argv[0])); /* No errors; no free! */ |
17 | 44 | return 0; |
18 | 44 | } |
19 | | |
20 | 4.49k | int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { |
21 | 4.49k | const u_int8_t *crypto_data; |
22 | 4.49k | uint64_t crypto_data_len; |
23 | 4.49k | u_int32_t first_int, version = 0; |
24 | | |
25 | 4.49k | if(ndpi_info_mod == NULL) { |
26 | 1 | fuzz_init_detection_module(&ndpi_info_mod, NULL, path); |
27 | | |
28 | 1 | flow = ndpi_calloc(1, SIZEOF_FLOW_STRUCT); |
29 | 1 | } |
30 | | |
31 | 4.49k | if(Size < 4) |
32 | 3 | return 0; |
33 | | |
34 | 4.49k | first_int = ntohl(*(u_int32_t *)Data); |
35 | 4.49k | if((first_int % 4) == 0) |
36 | 2.84k | version = 0x00000001; /* v1 */ |
37 | 1.65k | else if((first_int % 4) == 1) |
38 | 1.35k | version = 0x51303530; /* Q050 */ |
39 | 305 | else if((first_int % 4) == 2) |
40 | 249 | version = 0x51303436; /* Q046 */ |
41 | 56 | else if((first_int % 4) == 3) |
42 | 56 | version = 0x709A50C4; /* v2 */ |
43 | | |
44 | 4.49k | memset(flow, '\0', sizeof(*flow)); |
45 | 4.49k | flow->core.detected_protocol_stack[0] = NDPI_PROTOCOL_QUIC; |
46 | 4.49k | flow->core.l4_proto = IPPROTO_UDP; |
47 | 4.49k | flow->metadata.protos.tls_quic.quic_version = version; |
48 | | |
49 | 4.49k | crypto_data = get_crypto_data(ndpi_info_mod, flow, (u_int8_t *)Data + 4, Size - 4, &crypto_data_len); |
50 | | |
51 | 4.49k | if(crypto_data) { |
52 | 3.81k | if(!is_version_with_tls(version)) { |
53 | 1.38k | process_chlo(ndpi_info_mod, flow, crypto_data, crypto_data_len); |
54 | 2.42k | } else { |
55 | 2.42k | process_tls(ndpi_info_mod, flow, crypto_data, crypto_data_len); |
56 | 2.42k | } |
57 | 3.81k | } |
58 | | |
59 | 4.49k | ndpi_free_flow_data(flow); |
60 | | |
61 | 4.49k | return 0; |
62 | 4.49k | } |