/src/ndpi/fuzz/fuzz_community_id.cpp
Line | Count | Source |
1 | | #include "ndpi_api.h" |
2 | | #include "fuzz_common_code.h" |
3 | | |
4 | | #include <stdint.h> |
5 | | #include <stdio.h> |
6 | | #include <assert.h> |
7 | | #include "fuzzer/FuzzedDataProvider.h" |
8 | | |
9 | 470 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
10 | 470 | FuzzedDataProvider fuzzed_data(data, size); |
11 | 470 | u_int8_t is_ipv6, l4_proto, icmp_type, icmp_code; |
12 | 470 | u_int16_t src_port, dst_port; |
13 | 470 | u_char *hash_buf; |
14 | 470 | u_int8_t hash_buf_len; |
15 | | |
16 | | /* Just to have some data */ |
17 | | |
18 | | /* To allow memory allocation failures */ |
19 | 470 | fuzz_set_alloc_callbacks_and_seed(size); |
20 | | |
21 | 470 | is_ipv6 = fuzzed_data.ConsumeBool(); |
22 | 470 | l4_proto = fuzzed_data.ConsumeIntegral<u_int8_t>(); |
23 | 470 | src_port = fuzzed_data.ConsumeIntegral<u_int16_t>(); |
24 | 470 | dst_port = fuzzed_data.ConsumeIntegral<u_int16_t>(); |
25 | 470 | icmp_type = fuzzed_data.ConsumeIntegral<u_int8_t>(); |
26 | 470 | icmp_code = fuzzed_data.ConsumeIntegral<u_int8_t>(); |
27 | 470 | hash_buf_len = fuzzed_data.ConsumeIntegralInRange(0, 64); |
28 | 470 | hash_buf = (u_char *)ndpi_malloc(hash_buf_len); |
29 | 470 | if (!hash_buf) |
30 | 9 | return 0; |
31 | | |
32 | 461 | if (!is_ipv6) { |
33 | 213 | u_int32_t src_ip, dst_ip; |
34 | | |
35 | 213 | src_ip = fuzzed_data.ConsumeIntegral<u_int32_t>(); |
36 | 213 | dst_ip = fuzzed_data.ConsumeIntegral<u_int32_t>(); |
37 | | |
38 | 213 | ndpi_flowv4_flow_hash(l4_proto, src_ip, dst_ip, src_port, dst_port, |
39 | 213 | icmp_type, icmp_code, hash_buf, hash_buf_len); |
40 | 248 | } else { |
41 | 248 | u_char *src_ip, *dst_ip; |
42 | | |
43 | 248 | if(fuzzed_data.remaining_bytes() >= 32) { |
44 | 235 | std::vector<u_int8_t>data1 = fuzzed_data.ConsumeBytes<u_int8_t>(16); |
45 | 235 | src_ip = data1.data(); |
46 | 235 | std::vector<u_int8_t>data2 = fuzzed_data.ConsumeBytes<u_int8_t>(16); |
47 | 235 | dst_ip = data2.data(); |
48 | | |
49 | 235 | ndpi_flowv6_flow_hash(l4_proto, (struct ndpi_in6_addr *)src_ip, |
50 | 235 | (struct ndpi_in6_addr *)dst_ip, src_port, dst_port, |
51 | 235 | icmp_type, icmp_code, hash_buf, hash_buf_len); |
52 | 235 | } |
53 | 248 | } |
54 | | |
55 | 461 | ndpi_free(hash_buf); |
56 | | |
57 | 461 | return 0; |
58 | 470 | } |