#include <fcntl.h> /* open() O_RDONLY O_BINARY */
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#ifndef O_BINARY
#define O_BINARY 0 /* So it does nothing in Linux/Unix */
#endif
#include "dwarf.h"
#include "libdwarf.h"
int
LLVMFuzzerTestOneInput(
const
uint8_t *data,
size_t
size) {
char
filename[256];
sprintf
(filename,
"/tmp/libfuzzer.%d"
, getpid());
FILE
*fp =
fopen
(filename,
"wb"
);
if
(!fp) {
return
0;
}
fwrite
(data, size, 1, fp);
fclose
(fp);
Dwarf_Debug dbg = 0;
int
res = DW_DLV_ERROR;
Dwarf_Error error = 0;
Dwarf_Handler errhand = 0;
Dwarf_Ptr errarg = 0;
int
fd = open(filename, O_RDONLY | O_BINARY);
if
(fd < 0) {
exit
(EXIT_FAILURE);
}
res = dwarf_init_b(fd, DW_GROUPNUMBER_ANY, errhand, errarg, &dbg, &error);
if
(res != DW_DLV_OK) {
dwarf_dealloc_error(dbg, error);
}
else
{
Dwarf_Off dw_offset = 11;
char
*dw_string;
Dwarf_Signed dw_strlen_of_string;
while
((res = dwarf_get_str(dbg, dw_offset, &dw_string,
&dw_strlen_of_string, &error)) == DW_DLV_OK) {
dw_offset += dw_strlen_of_string + 1;
}
}
dwarf_finish(dbg);
close(fd);
unlink(filename);
return
0;
}