Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright 2021 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 | | #include <stdint.h> |
13 | | #include <stdio.h> |
14 | | #include <stdlib.h> |
15 | | #include <string.h> |
16 | | #include <sys/types.h> |
17 | | #include <sys/stat.h> |
18 | | #include <fcntl.h> |
19 | | #include <unistd.h> |
20 | | |
21 | | /* |
22 | | * Libdwarf library callers can only use these headers. |
23 | | */ |
24 | | #include "dwarf.h" |
25 | | #include "libdwarf.h" |
26 | | |
27 | | /* |
28 | | * A fuzzer that simulates a small part of the simplereader.c example. |
29 | | * This fuzzer targets dwarf_init_b. |
30 | | */ |
31 | 9.01k | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
32 | 9.01k | char filename[256]; |
33 | 9.01k | sprintf(filename, "/tmp/libfuzzer.%d", getpid()); |
34 | | |
35 | 9.01k | FILE *fp = fopen(filename, "wb"); |
36 | 9.01k | if (!fp) { |
37 | 0 | return 0; |
38 | 0 | } |
39 | 9.01k | fwrite(data, size, 1, fp); |
40 | 9.01k | fclose(fp); |
41 | | |
42 | 9.01k | int my_init_fd = 0; |
43 | 9.01k | Dwarf_Ptr errarg = 0; |
44 | 9.01k | Dwarf_Handler errhand = 0; |
45 | 9.01k | Dwarf_Error *errp = NULL; |
46 | 9.01k | Dwarf_Debug dbg = 0; |
47 | | |
48 | 9.01k | my_init_fd = open(filename, O_RDONLY); |
49 | 9.01k | if (my_init_fd != -1) { |
50 | 9.01k | dwarf_init_b(my_init_fd,DW_GROUPNUMBER_ANY,errhand,errarg,&dbg,errp); |
51 | 9.01k | dwarf_finish(dbg); |
52 | 9.01k | close(my_init_fd); |
53 | 9.01k | } |
54 | | |
55 | 9.01k | unlink(filename); |
56 | 9.01k | return 0; |
57 | 9.01k | } |