Coverage Report

Created: 2025-07-11 06:46

/src/fuzz-libdwfl.c
Line
Count
Source
1
/* Copyright 2022 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
13
#include <assert.h>
14
#include <fcntl.h>
15
#include <gelf.h>
16
#include <inttypes.h>
17
#include <libelf.h>
18
#include <stdio.h>
19
#include <stdlib.h>
20
#include <string.h>
21
#include <sys/stat.h>
22
#include <sys/types.h>
23
#include <unistd.h>
24
#include "libdwfl.h"
25
#include "system.h"
26
27
static const char *debuginfo_path = "";
28
static const Dwfl_Callbacks cb  = {
29
  NULL,
30
  dwfl_standard_find_debuginfo,
31
  NULL,
32
  (char **)&debuginfo_path,
33
};
34
35
36
15.9k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
37
15.9k
  char filename[] = "/tmp/fuzz-libdwfl.XXXXXX";
38
15.9k
  int fd;
39
15.9k
  ssize_t n;
40
41
15.9k
  fd = mkstemp(filename);
42
15.9k
  assert(fd >= 0);
43
44
15.9k
  n = write_retry(fd, data, size);
45
15.9k
  assert(n == (ssize_t) size);
46
47
15.9k
  close(fd);
48
49
15.9k
  Dwarf_Addr bias = 0;
50
15.9k
  Dwfl *dwfl = dwfl_begin(&cb);
51
15.9k
  dwfl_report_begin(dwfl);
52
53
15.9k
  Dwfl_Module *mod = dwfl_report_offline(dwfl, filename, filename, -1);
54
15.9k
  dwfl_module_getdwarf(mod, &bias);
55
56
15.9k
  dwfl_end (dwfl);
57
15.9k
  unlink(filename);
58
15.9k
  return 0;
59
15.9k
}