Coverage Report

Created: 2023-06-07 07:08

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