Debian Codegraph @

fuzz/fuzz_simplereader_tu.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 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
28 char filename[256];
29 sprintf(filename, "/tmp/libfuzzer.%d", getpid());
30
31 FILE *fp = fopen(filename, "wb");
32 if (!fp) {
33 return 0;
34 }
35 fwrite(data, size, 1, fp);
36 fclose(fp);
37
38 Dwarf_Debug dbg = 0;
39 int fuzz_fd = 0;
40 int res = DW_DLV_ERROR;
41 Dwarf_Error error = 0;
42 Dwarf_Handler errhand = 0;
43 Dwarf_Ptr errarg = 0;
44 Dwarf_Sig8 hash8;
45 Dwarf_Sig8 hash8_2;
46 Dwarf_Error *errp = 0;
47 Dwarf_Die die = 0;
48 Dwarf_Attribute attr = 0;
49
50 fuzz_fd = open(filename, O_RDONLY|O_BINARY);
51 if (fuzz_fd != -1) {
52 Dwarf_Debug_Fission_Per_CU fisdata;
53 memset(&fisdata, 0, sizeof(fisdata));
54 res = dwarf_die_from_hash_signature(dbg, &hash8, "tu", &die, errp);
55 res = dwarf_get_debugfission_for_key(dbg, &hash8_2, "tu", &fisdata, errp);
56 Dwarf_Addr uval = 0;
57 res = dwarf_formaddr(attr, &uval, errp);
58 dwarf_dealloc(dbg, die, DW_DLA_DIE);
59 dwarf_finish(dbg);
60 }
61 close(fuzz_fd);
62 unlink(filename);
63 return 0;
64 }