Debian Codegraph @

fuzz/fuzz_stack_frame_access.c

raw
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 "dwarf.h"
13 #include "libdwarf.h"
14 #include <fcntl.h> /* open() O_RDONLY O_BINARY */
15 #include <stdint.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <sys/stat.h>
20 #include <sys/types.h>
21 #include <unistd.h>
22
23 #ifndef O_BINARY
24 #define O_BINARY 0
25 #endif
26
27
28 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
29 char filename[256];
30 sprintf(filename, "/tmp/libfuzzer.%d", getpid());
31
32 FILE *fp = fopen(filename, "wb");
33 if (!fp) {
34 return 0;
35 }
36 fwrite(data, size, 1, fp);
37 fclose(fp);
38
39 Dwarf_Debug dbg = 0;
40 int fuzz_fd = 0;
41 int res = DW_DLV_ERROR;
42 Dwarf_Error error = 0;
43 Dwarf_Handler errhand = 0;
44 Dwarf_Ptr errarg = 0;
45 Dwarf_Error *errp = 0;
46 int i = 0;
47 Dwarf_Die die;
48
49 fuzz_fd = open(filename, O_RDONLY|O_BINARY);
50 if (fuzz_fd != -1) {
51 res =
52 dwarf_init_b(fuzz_fd, DW_GROUPNUMBER_ANY, errhand, errarg, &dbg, errp);
53 if (res == DW_DLV_OK) {
54 Dwarf_Bool is_info = 0;
55 Dwarf_Unsigned cu_header_length = 0;
56 Dwarf_Half version_stamp = 0;
57 Dwarf_Off abbrev_offset = 0;
58 Dwarf_Half address_size = 0;
59 Dwarf_Half length_size = 0;
60 Dwarf_Half extension_size = 0;
61 Dwarf_Sig8 type_signature;
62 Dwarf_Unsigned typeoffset = 0;
63 Dwarf_Unsigned next_cu_header_offset = 0;
64 Dwarf_Half header_cu_type = 0;
65 int res = 0;
66 Dwarf_Die cu_die = 0;
67 int level = 0;
68 static const Dwarf_Sig8 zerosignature;
69
70 type_signature = zerosignature;
71 res = dwarf_next_cu_header_d(
72 dbg, is_info, &cu_header_length, &version_stamp, &abbrev_offset,
73 &address_size, &length_size, &extension_size, &type_signature,
74 &typeoffset, &next_cu_header_offset, &header_cu_type, errp);
75 if (res == DW_DLV_OK) {
76 res = dwarf_siblingof_b(dbg, NULL, is_info, &cu_die, errp);
77 if (res == DW_DLV_OK) {
78 Dwarf_Fde dw_returned_fde;
79 dwarf_get_fde_for_die(dbg, cu_die, &dw_returned_fde, errp);
80 } else {
81 }
82 dwarf_dealloc(dbg, cu_die, DW_DLA_DIE);
83 }
84 }
85 }
86 dwarf_finish(dbg);
87 close(fuzz_fd);
88 unlink(filename);
89 return 0;
90 }