Coverage Report

Created: 2026-09-14 08:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/binutils/fuzz_objdump.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
13
/*
14
 * We convert objdump.c into a header file to make convenient for fuzzing.
15
 * We do this for several of the binutils applications when creating
16
 * the binutils fuzzers.
17
 */
18
#include "fuzz_objdump.h"
19
20
32.8k
void objdump_reset() {
21
32.8k
  process_links = true;
22
32.8k
  do_follow_links = true;
23
32.8k
  dump_section_contents = true;
24
32.8k
  dump_section_headers = true;
25
32.8k
  dump_private_headers = true;
26
32.8k
  dump_ar_hdrs = true;
27
32.8k
  dump_dwarf_section_info = true;
28
  // We must call both dwarf_select_sections_by_letters and dwarf_select_sections_all
29
  // since dwarf_select_sections_all does not set do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
30
32.8k
  dwarf_select_sections_by_letters("L");
31
32.8k
  dwarf_select_sections_all ();
32
32.8k
  dump_debugging = true;
33
34
32.8k
  dump_stab_section_info = true;
35
32.8k
  disassemble_all = true;
36
32.8k
}
37
38
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
39
int
40
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
41
128k
{
42
128k
  if (size > 16384)
43
88
    return 0;
44
128k
  char filename[256];
45
128k
  sprintf(filename, "/tmp/libfuzzer.%d", getpid());
46
128k
  FILE *fp = fopen(filename, "wb");
47
128k
  if (!fp) {
48
0
    return 0;
49
0
  }
50
128k
  fwrite(data, size, 1, fp);
51
128k
  fclose(fp);
52
53
128k
  program_name = filename;
54
55
128k
  objdump_reset();
56
57
  // These flags contain a large set of calls to bfd_fatal (which calls
58
  // exit), so to enable fuzzing of objdump with a fuzzer that lives for
59
  // a longer period of time (more than 10 seconds) define
60
  // OBJDUMP_SAFE
61
128k
#ifndef OBJDUMP_SAFE
62
128k
  dump_reloc_info = true;
63
  // ctf section and reloc are simply too quick to exit and disrupts
64
  // fuzzing too much. Will leave this commented out for now.
65
  //dump_dynamic_reloc_info = true;
66
  //dump_ctf_section_info = true;
67
128k
  disassemble = true;
68
128k
#endif
69
70
  // Main fuzz entrypoint in objdump.c
71
128k
  display_file(filename, NULL);
72
73
128k
  unlink(filename);
74
128k
  return 0;
75
128k
}