]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/standalone_fuzz_target_runner.cc
8 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data
, size_t size
);
9 extern "C" __attribute__((weak
)) int LLVMFuzzerInitialize(int* argc
, char*** argv
);
11 int main(int argc
, char** argv
)
13 std::cerr
<<"StandaloneFuzzTargetMain: running "<<(argc
-1)<<" inputs"<<std::endl
;
15 if (LLVMFuzzerInitialize
) {
16 LLVMFuzzerInitialize(&argc
, &argv
);
19 for (int i
= 1; i
< argc
; i
++) {
22 if (stat(argv
[i
], &st
) || !S_ISREG(st
.st_mode
)) {
23 std::cerr
<<"Skipping non-regular file: "<<std::string(argv
[i
])<<std::endl
;
27 std::cerr
<<"Running: "<<std::string(argv
[i
])<<std::endl
;
29 std::ifstream
file(argv
[i
], std::ios::binary
);
30 file
.seekg(0, std::ios::end
);
31 size_t fileSize
= file
.tellg();
32 file
.seekg(0, std::ios::beg
);
34 std::vector
<char> buffer
;
35 buffer
.resize(fileSize
);
37 file
.read(reinterpret_cast<char*>(buffer
.data()), fileSize
);
41 throw std::runtime_error("Error reading fuzzing input from file '" + std::string(argv
[i
]) + '"');
46 LLVMFuzzerTestOneInput(reinterpret_cast<const uint8_t*>(buffer
.data()), fileSize
);
48 std::cerr
<<"Done: '"<<std::string(argv
[i
])<<"': ("<<fileSize
<<" bytes)"<<std::endl
;