/src/binutils-gdb/binutils/fuzz_strings.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 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 | 64.6k | { |
24 | 64.6k | if (size > 16384) |
25 | 94 | return 0; |
26 | 64.5k | char filename[256]; |
27 | 64.5k | sprintf(filename, "/tmp/libfuzzer.%d", getpid()); |
28 | 64.5k | FILE *fp = fopen(filename, "wb"); |
29 | 64.5k | if (!fp) { |
30 | 0 | return 0; |
31 | 0 | } |
32 | 64.5k | fwrite(data, size, 1, fp); |
33 | 64.5k | fclose(fp); |
34 | | |
35 | 64.5k | program_name = "fuzz_strings"; |
36 | | |
37 | 64.5k | string_min = 4; |
38 | 64.5k | encoding = 's'; |
39 | 64.5k | encoding_bytes = 1; |
40 | 64.5k | datasection_only = true; |
41 | | |
42 | | // Main fuzz entrypoint in strings.c |
43 | 64.5k | strings_object_file(filename); |
44 | | |
45 | 64.5k | unlink(filename); |
46 | 64.5k | return 0; |
47 | 64.5k | } |