/src/rtpproxy/scripts/fuzz/fuzz_standalone.h
Line | Count | Source |
1 | | #pragma once |
2 | | |
3 | | #if defined(FUZZ_STANDALONE) |
4 | | #include <assert.h> |
5 | | #include <fcntl.h> |
6 | | #include <stdlib.h> |
7 | | #include <string.h> |
8 | | #include <unistd.h> |
9 | | #endif /* FUZZ_STANDALONE */ |
10 | | |
11 | | const int rtpp_is_lib = 0; |
12 | | const int rtpp_use_smodules = 1; |
13 | | |
14 | | #if defined(FUZZ_STANDALONE) |
15 | | extern int LLVMFuzzerInitialize(int *argc, char ***argv) __attribute__((__weak__)); |
16 | | |
17 | | int LLVMFuzzerTestOneInput(const char *data, size_t size); |
18 | | |
19 | | __attribute__((constructor)) static void |
20 | | rtpp_init() |
21 | | { |
22 | | if (LLVMFuzzerInitialize != NULL) { |
23 | | int r = LLVMFuzzerInitialize(NULL, NULL); |
24 | | if (r != 0) |
25 | | abort(); |
26 | | } |
27 | | } |
28 | | |
29 | | int |
30 | | main(int argc, char *argv[]) |
31 | | { |
32 | | int fflag, ch, fd; |
33 | | char buf[1024], *cp; |
34 | | size_t size; |
35 | | |
36 | | fflag = 0; |
37 | | while ((ch = getopt(argc, argv, "f")) != -1) { |
38 | | switch (ch) { |
39 | | case 'f': |
40 | | fflag = 1; |
41 | | break; |
42 | | default: |
43 | | return (-1); |
44 | | } |
45 | | } |
46 | | argc -= optind; |
47 | | argv += optind; |
48 | | |
49 | | assert(argc == 1); |
50 | | if (fflag) { |
51 | | fd = open(argv[0], O_RDONLY, 0); |
52 | | assert(fd >= 0); |
53 | | size = read(fd, buf, sizeof(buf)); |
54 | | assert(size > 0); |
55 | | cp = buf; |
56 | | } else { |
57 | | cp = argv[0]; |
58 | | size = strlen(cp); |
59 | | } |
60 | | LLVMFuzzerTestOneInput(cp, size); |
61 | | return (0); |
62 | | } |
63 | | #else |
64 | 0 | const char *__asan_default_options() { |
65 | 0 | return "verbosity=0"; |
66 | 0 | } |
67 | | #endif /* FUZZ_STANDALONE */ |