Coverage Report

Created: 2022-11-25 06:09

/src/fuzz_init_path.c
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 <unistd.h>
18
19
/*
20
 * Libdwarf library callers can only use these headers.
21
 */
22
#include "dwarf.h"
23
#include "libdwarf.h"
24
25
/*
26
 * A fuzzer that simulates a small part of the simplereader.c example.
27
 */
28
6.25k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
29
6.25k
  char filename[256];
30
6.25k
  sprintf(filename, "/tmp/libfuzzer.%d", getpid());
31
32
6.25k
  FILE *fp = fopen(filename, "wb");
33
6.25k
  if (!fp) {
34
0
    return 0;
35
0
  }
36
6.25k
  fwrite(data, size, 1, fp);
37
6.25k
  fclose(fp);
38
6.25k
  Dwarf_Ptr errarg = 0;
39
6.25k
  Dwarf_Handler errhand = 0;
40
6.25k
  Dwarf_Debug dbg = 0;
41
6.25k
  Dwarf_Error *errp = NULL;
42
6.25k
#define MACHO_PATH_LEN 2000
43
6.25k
  char macho_real_path[2000];
44
6.25k
  dwarf_init_path(filename, macho_real_path, MACHO_PATH_LEN,
45
6.25k
                  DW_GROUPNUMBER_ANY, errhand, errarg, &dbg, errp);
46
47
6.25k
  dwarf_finish(dbg);
48
49
6.25k
  unlink(filename);
50
6.25k
  return 0;
51
6.25k
}