Coverage Report

Created: 2023-08-28 06:25

/src/binutils-gdb/binutils/fuzz_strings.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 strings.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_strings.h"
19
20
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
21
int
22
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
23
336
{
24
336
  char filename[256];
25
336
  sprintf(filename, "/tmp/libfuzzer.%d", getpid());
26
336
  FILE *fp = fopen(filename, "wb");
27
336
  if (!fp) {
28
0
    return 0;
29
0
  }
30
336
  fwrite(data, size, 1, fp);
31
336
  fclose(fp);
32
33
336
  program_name = "fuzz_strings";
34
35
  // Main fuzz entrypoint in strings.c
36
336
  strings_object_file(filename);
37
38
336
  unlink(filename);
39
336
  return 0;
40
336
}