/src/ndpi/fuzz/fuzz_dga.c
Line | Count | Source (jump to first uncovered line) |
1 | | #include "ndpi_api.h" |
2 | | #include "fuzz_common_code.h" |
3 | | |
4 | | static struct ndpi_detection_module_struct *ndpi_struct = NULL; |
5 | | static struct ndpi_flow_struct *ndpi_flow = NULL; |
6 | | |
7 | | static int ndpi_custom_dga_fn(const char* domain, int domain_length) |
8 | 18 | { |
9 | 18 | return ndpi_is_printable_buffer((const u_int8_t *)domain, domain_length); |
10 | 18 | } |
11 | | |
12 | 930 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
13 | 930 | char *name; |
14 | | |
15 | 930 | if (ndpi_struct == NULL) { |
16 | 1 | fuzz_init_detection_module(&ndpi_struct, NULL); |
17 | 1 | ndpi_flow = ndpi_calloc(1, sizeof(struct ndpi_flow_struct)); |
18 | 1 | } |
19 | | |
20 | 930 | if (size == 0) |
21 | 0 | return 0; |
22 | | |
23 | 930 | if (data[0] % 2 == 0) |
24 | 18 | ndpi_dga_function = ndpi_custom_dga_fn; |
25 | 912 | else |
26 | 912 | ndpi_dga_function = NULL; |
27 | | |
28 | 930 | name = ndpi_malloc(size + 1); |
29 | 930 | if (name) { |
30 | 930 | memcpy(name, data, size); |
31 | 930 | name[size] = '\0'; |
32 | 930 | ndpi_check_dga_name(ndpi_struct, ndpi_flow, name, 1, 1, 0); |
33 | 930 | ndpi_free(name); |
34 | 930 | } |
35 | | |
36 | 930 | return 0; |
37 | 930 | } |