Coverage Report

Created: 2025-10-10 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fuzz-dwfl-core.c
Line
Count
Source
1
/*
2
# Copyright 2021 Google Inc.
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
#      http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
#
16
################################################################################
17
*/
18
#include <assert.h>
19
#include <config.h>
20
#include <stdlib.h>
21
#include <unistd.h>
22
#include ELFUTILS_HEADER(dwfl)
23
24
static const Dwfl_Callbacks core_callbacks = {
25
  .find_elf = dwfl_build_id_find_elf,
26
  .find_debuginfo = dwfl_standard_find_debuginfo,
27
};
28
29
16.0k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
30
16.0k
  char name[] = "/tmp/fuzz-dwfl-core.XXXXXX";
31
16.0k
  int fd = -1;
32
16.0k
  ssize_t n;
33
16.0k
  off_t offset;
34
16.0k
  Elf *core = NULL;
35
16.0k
  Dwfl *dwfl = NULL;
36
37
16.0k
  fd = mkstemp(name);
38
16.0k
  assert(fd >= 0);
39
40
16.0k
  n = write(fd, data, size);
41
16.0k
  assert(n == (ssize_t) size);
42
43
16.0k
  offset = lseek(fd, 0, SEEK_SET);
44
16.0k
  assert(offset == 0);
45
46
16.0k
  elf_version(EV_CURRENT);
47
16.0k
  core = elf_begin(fd, ELF_C_READ_MMAP, NULL);
48
16.0k
  if (core == NULL)
49
72
    goto cleanup;
50
15.9k
  dwfl = dwfl_begin(&core_callbacks);
51
15.9k
  assert(dwfl != NULL);
52
15.9k
  if (dwfl_core_file_report(dwfl, core, NULL) < 0)
53
1.01k
    goto cleanup;
54
14.9k
  if (dwfl_report_end(dwfl, NULL, NULL) != 0)
55
0
    goto cleanup;
56
14.9k
  if (dwfl_core_file_attach(dwfl, core) < 0)
57
14.8k
    goto cleanup;
58
59
16.0k
cleanup:
60
16.0k
  dwfl_end(dwfl);
61
16.0k
  elf_end(core);
62
16.0k
  close(fd);
63
16.0k
  unlink(name);
64
16.0k
  return 0;
65
14.9k
}