Coverage Report

Created: 2026-01-09 06:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libdwarf/fuzz/fuzz_tie.c
Line
Count
Source
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 <fcntl.h> /* open() O_RDONLY O_BINARY */
13
#include <stdint.h>
14
#include <stdio.h>
15
#include <stdlib.h>
16
#include <string.h>
17
#include <sys/stat.h>
18
#include <sys/types.h>
19
#include <unistd.h>
20
#include "dwarf.h"
21
#include "libdwarf.h"
22
23
#ifndef O_BINARY
24
8.10k
#define O_BINARY 0
25
#endif
26
27
8.10k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
28
8.10k
  char filename[256];
29
30
#ifdef DWREGRESSIONTEMP
31
  /*  Under msys2, the /tmp/ results in an open fail,
32
      so we discard the /tmp/ here */
33
  sprintf(filename, "junklibfuzzer.%d", getpid());
34
#else
35
8.10k
  sprintf(filename, "/tmp/libfuzzer.%d", getpid());
36
8.10k
#endif
37
8.10k
  FILE *fp = fopen(filename, "wb");
38
8.10k
  if (!fp) {
39
0
    printf("FAIL libfuzzer cannot open temp as writeable %s\n",
40
0
        filename);
41
0
    return 0;
42
0
  }
43
8.10k
  fwrite(data, size, 1, fp);
44
8.10k
  fclose(fp);
45
46
8.10k
  int fuzz_fd = 0;
47
8.10k
  Dwarf_Ptr errarg = 0;
48
8.10k
  Dwarf_Handler errhand = 0;
49
8.10k
  Dwarf_Error *errp = NULL;
50
8.10k
  Dwarf_Debug dbg = 0;
51
52
8.10k
  fuzz_fd = open(filename, O_RDONLY|O_BINARY);
53
8.10k
  if (fuzz_fd != -1) {
54
8.10k
    int res =
55
8.10k
        dwarf_init_b(fuzz_fd, DW_GROUPNUMBER_ANY, errhand, errarg, &dbg, errp);
56
8.10k
    if (res == DW_DLV_OK) {
57
213
      res = dwarf_set_tied_dbg(dbg, NULL, errp);
58
213
    }
59
8.10k
    dwarf_finish(dbg);
60
8.10k
    close(fuzz_fd);
61
8.10k
  }
62
63
8.10k
  unlink(filename);
64
8.10k
  return 0;
65
8.10k
}