diff options
| author | robot-piglet <[email protected]> | 2023-05-26 18:02:46 +0300 |
|---|---|---|
| committer | robot-piglet <[email protected]> | 2023-05-26 18:02:46 +0300 |
| commit | d85fbebd3ea97ba43da1f6d672dde2b18347f11a (patch) | |
| tree | 592f624cde6617872108479e43b781b2e16b565c /contrib/libs/libfuzzer/lib/fuzzer/standalone | |
| parent | d8341f8abab29d0fcfb7096a3d1b3c6fd399781b (diff) | |
Intermediate changes
Diffstat (limited to 'contrib/libs/libfuzzer/lib/fuzzer/standalone')
| -rw-r--r-- | contrib/libs/libfuzzer/lib/fuzzer/standalone/StandaloneFuzzTargetMain.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/contrib/libs/libfuzzer/lib/fuzzer/standalone/StandaloneFuzzTargetMain.c b/contrib/libs/libfuzzer/lib/fuzzer/standalone/StandaloneFuzzTargetMain.c new file mode 100644 index 00000000000..0417cc43f7f --- /dev/null +++ b/contrib/libs/libfuzzer/lib/fuzzer/standalone/StandaloneFuzzTargetMain.c @@ -0,0 +1,46 @@ +/*===- StandaloneFuzzTargetMain.c - standalone main() for fuzz targets. ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// This main() function can be linked to a fuzz target (i.e. a library +// that exports LLVMFuzzerTestOneInput() and possibly LLVMFuzzerInitialize()) +// instead of libFuzzer. This main() function will not perform any fuzzing +// but will simply feed all input files one by one to the fuzz target. +// +// Use this file to provide reproducers for bugs when linking against libFuzzer +// or other fuzzing engine is undesirable. +//===----------------------------------------------------------------------===*/ +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> + +extern int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size); +#ifndef _MSC_VER +__attribute__((weak)) +extern int LLVMFuzzerInitialize(int *argc, char ***argv); +#endif +int main(int argc, char **argv) { + fprintf(stderr, "StandaloneFuzzTargetMain: running %d inputs\n", argc - 1); +#ifndef _MSC_VER + if (LLVMFuzzerInitialize) + LLVMFuzzerInitialize(&argc, &argv); +#endif + for (int i = 1; i < argc; i++) { + fprintf(stderr, "Running: %s\n", argv[i]); + FILE *f = fopen(argv[i], "r"); + assert(f); + fseek(f, 0, SEEK_END); + size_t len = ftell(f); + fseek(f, 0, SEEK_SET); + unsigned char *buf = (unsigned char*)malloc(len); + size_t n_read = fread(buf, 1, len, f); + fclose(f); + assert(n_read == len); + LLVMFuzzerTestOneInput(buf, len); + free(buf); + fprintf(stderr, "Done: %s: (%zd bytes)\n", argv[i], n_read); + } +} |
