/src/kamailio/misc/fuzz/fuzz_pv_parse.c
Line | Count | Source |
1 | | #include "../config.h" |
2 | | #include "../pvar.h" |
3 | | |
4 | | #include <stdint.h> |
5 | | #include <stdlib.h> |
6 | | #include <string.h> |
7 | | |
8 | | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
9 | 514 | { |
10 | 514 | if(size < 2 || size > 4096) { |
11 | 20 | return 0; |
12 | 20 | } |
13 | | |
14 | | /* Make a mutable copy. */ |
15 | 494 | char *buf = (char *)malloc(size + 1); |
16 | 494 | if(buf == NULL) { |
17 | 0 | return 0; |
18 | 0 | } |
19 | 494 | memcpy(buf, data, size); |
20 | 494 | buf[size] = '\0'; |
21 | | |
22 | 494 | str input; |
23 | 494 | input.s = buf; |
24 | 494 | input.len = (int)size; |
25 | | |
26 | 494 | pv_elem_p elements = NULL; |
27 | | |
28 | 494 | pv_parse_format(&input, &elements); |
29 | | |
30 | 494 | if(elements) { |
31 | 45 | pv_elem_free_all(elements); |
32 | 45 | } |
33 | | |
34 | 494 | free(buf); |
35 | 494 | return 0; |
36 | 494 | } |