Coverage Report

Created: 2025-07-11 06:09

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