Line | Count | Source |
1 | | /* Copyright 2022 Google LLC |
2 | | Licensed under the Apache License, Version 2.0 (the "License"); |
3 | | you may not use this file except in compliance with the License. |
4 | | You may obtain a copy of the License at |
5 | | http://www.apache.org/licenses/LICENSE-2.0 |
6 | | Unless required by applicable law or agreed to in writing, software |
7 | | distributed under the License is distributed on an "AS IS" BASIS, |
8 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
9 | | See the License for the specific language governing permissions and |
10 | | limitations under the License. |
11 | | */ |
12 | | |
13 | | #include <assert.h> |
14 | | #include <fcntl.h> |
15 | | #include <gelf.h> |
16 | | #include <inttypes.h> |
17 | | #include <libelf.h> |
18 | | #include <stdio.h> |
19 | | #include <stdlib.h> |
20 | | #include <string.h> |
21 | | #include <sys/stat.h> |
22 | | #include <sys/types.h> |
23 | | #include <unistd.h> |
24 | | #include "libdwfl.h" |
25 | | #include "system.h" |
26 | | |
27 | | static const char *debuginfo_path = ""; |
28 | | static const Dwfl_Callbacks cb = { |
29 | | NULL, |
30 | | dwfl_standard_find_debuginfo, |
31 | | NULL, |
32 | | (char **)&debuginfo_path, |
33 | | }; |
34 | | |
35 | | |
36 | 10.1k | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
37 | 10.1k | char filename[] = "/tmp/fuzz-libdwfl.XXXXXX"; |
38 | 10.1k | int fd; |
39 | 10.1k | ssize_t n; |
40 | | |
41 | 10.1k | fd = mkstemp(filename); |
42 | 10.1k | assert(fd >= 0); |
43 | | |
44 | 10.1k | n = write_retry(fd, data, size); |
45 | 10.1k | assert(n == (ssize_t) size); |
46 | | |
47 | 10.1k | close(fd); |
48 | | |
49 | 10.1k | Dwarf_Addr bias = 0; |
50 | 10.1k | Dwfl *dwfl = dwfl_begin(&cb); |
51 | 10.1k | dwfl_report_begin(dwfl); |
52 | | |
53 | 10.1k | Dwfl_Module *mod = dwfl_report_offline(dwfl, filename, filename, -1); |
54 | 10.1k | dwfl_module_getdwarf(mod, &bias); |
55 | | |
56 | 10.1k | dwfl_end (dwfl); |
57 | 10.1k | unlink(filename); |
58 | 10.1k | return 0; |
59 | 10.1k | } |