LLVM
4.0.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
llvm.src
lib
Fuzzer
standalone
StandaloneFuzzTargetMain.c
Go to the documentation of this file.
1
/*===- StandaloneFuzzTargetMain.c - standalone main() for fuzz targets. ---===//
2
//
3
// The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
// This main() function can be linked to a fuzz target (i.e. a library
10
// that exports LLVMFuzzerTestOneInput() and possibly LLVMFuzzerInitialize())
11
// instead of libFuzzer. This main() function will not perform any fuzzing
12
// but will simply feed all input files one by one to the fuzz target.
13
//
14
// Use this file to provide reproducers for bugs when linking against libFuzzer
15
// or other fuzzing engine is undesirable.
16
//===----------------------------------------------------------------------===*/
17
#include <assert.h>
18
#include <stdio.h>
19
#include <stdlib.h>
20
21
extern
int
LLVMFuzzerTestOneInput
(
const
unsigned
char
*data,
size_t
size);
22
__attribute__
((weak)) extern
int
LLVMFuzzerInitialize
(
int
*argc,
char
***
argv
);
23
int
main
(
int
argc,
char
**argv) {
24
fprintf(stderr,
"StandaloneFuzzTargetMain: running %d inputs\n"
, argc - 1);
25
if
(
LLVMFuzzerInitialize
)
26
LLVMFuzzerInitialize
(&argc, &argv);
27
for
(
int
i
= 1;
i
< argc;
i
++) {
28
fprintf(stderr,
"Running: %s\n"
, argv[
i
]);
29
FILE *f = fopen(argv[i],
"r"
);
30
assert
(f);
31
fseek(f, 0, SEEK_END);
32
size_t
len = ftell(f);
33
fseek(f, 0, SEEK_SET);
34
unsigned
char
*buf = (
unsigned
char
*)malloc(len);
35
size_t
n_read = fread(buf, 1, len, f);
36
assert
(n_read == len);
37
LLVMFuzzerTestOneInput
(buf, len);
38
free(buf);
39
fprintf(stderr,
"Done: %s: (%zd bytes)\n"
, argv[i], n_read);
40
}
41
}
i
size_t i
Definition:
FuzzerTracePC.cpp:312
LLVMFuzzerTestOneInput
int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size)
main
int main(int argc, char **argv)
Definition:
afl_driver.cpp:241
argv
char *** argv
Definition:
afl_driver.cpp:87
LLVMFuzzerInitialize
int LLVMFuzzerInitialize(int *argc, char ***argv)
Definition:
AFLDriverTest.cpp:16
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
__attribute__
__attribute__((weak))
Definition:
StandaloneFuzzTargetMain.c:22
Generated on Wed Mar 8 2017 17:28:30 for LLVM by
1.8.6