Coverage Report

Created: 2025-06-24 06:45

/src/binutils-gdb/binutils/fuzz_addr2line.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
13
/*
14
 * We convert addr2line.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_addr2line.h"
19
20
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
21
int
22
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
23
36.6k
{
24
36.6k
  char filename[256];
25
36.6k
  sprintf(filename, "/tmp/libfuzzer.%d", getpid());
26
36.6k
  FILE *fp = fopen(filename, "wb");
27
36.6k
  if (!fp) {
28
0
    return 0;
29
0
  }
30
36.6k
  fwrite(data, size, 1, fp);
31
36.6k
  fclose(fp);
32
33
36.6k
  program_name = filename;
34
35
36.6k
  char **c2 = xmalloc(sizeof(char*)*6);
36
36.6k
  c2[0] = xstrdup("AAABC");
37
36.6k
  c2[1] = xstrdup("BBC");
38
36.6k
  c2[2] = xstrdup("0xbeefbeef");
39
36.6k
  c2[3] = xstrdup("0xcafebabe");
40
36.6k
  c2[4] = xstrdup("5123423");
41
36.6k
  c2[5] = NULL;
42
43
36.6k
  naddr = 5;
44
36.6k
  addr = c2;
45
46
  // Main fuzz entrypoint in addr2line.c
47
36.6k
  process_file(filename, NULL, NULL);
48
49
220k
  for (int i = 5; --i >= 0; )
50
183k
    free(c2[i]);
51
36.6k
  free(c2);
52
53
36.6k
  unlink(filename);
54
36.6k
  return 0;
55
36.6k
}