/src/ndpi/fuzz/fuzz_dga_url.c
Line | Count | Source |
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 char *path = NULL; |
8 | | |
9 | 44 | int LLVMFuzzerInitialize(int *argc, char ***argv) { |
10 | 44 | (void)argc; |
11 | | |
12 | 44 | path = dirname(strdup(*argv[0])); /* No errors; no free! */ |
13 | 44 | return 0; |
14 | 44 | } |
15 | | |
16 | 606 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
17 | 606 | char *name; |
18 | | |
19 | 606 | if (ndpi_struct == NULL) { |
20 | 1 | fuzz_init_detection_module(&ndpi_struct, NULL, path); |
21 | 1 | ndpi_flow = ndpi_calloc(1, sizeof(struct ndpi_flow_struct)); |
22 | 1 | } |
23 | | |
24 | 606 | if (size == 0) |
25 | 0 | return 0; |
26 | | |
27 | 606 | name = ndpi_malloc(size + 1); |
28 | 606 | if (name) { |
29 | 606 | memcpy(name, data, size); |
30 | 606 | name[size] = '\0'; |
31 | 606 | ndpi_check_dga_url_path(ndpi_struct, ndpi_flow, name); |
32 | 606 | ndpi_free(name); |
33 | 606 | } |
34 | | |
35 | 606 | return 0; |
36 | 606 | } |