##// END OF EJS Templates
fuzz: make standalone_fuzz_target_runner call LLVMFuzzerInitialize...
Augie Fackler -
r44253:01ec70a8 default draft
parent child Browse files
Show More
@@ -1,41 +1,45
1 1 // Copyright 2017 Google Inc. All Rights Reserved.
2 2 // Licensed under the Apache License, Version 2.0 (the "License");
3 3
4 4 // Example of a standalone runner for "fuzz targets".
5 5 // It reads all files passed as parameters and feeds their contents
6 6 // one by one into the fuzz target (LLVMFuzzerTestOneInput).
7 7 // This runner does not do any fuzzing, but allows us to run the fuzz target
8 8 // on the test corpus (e.g. "do_stuff_test_data") or on a single file,
9 9 // e.g. the one that comes from a bug report.
10 10
11 11 #include <cassert>
12 12 #include <fstream>
13 13 #include <iostream>
14 14 #include <vector>
15 15
16 16 // Forward declare the "fuzz target" interface.
17 17 // We deliberately keep this inteface simple and header-free.
18 18 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
19 19
20 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv);
21
20 22 int main(int argc, char **argv)
21 23 {
24 LLVMFuzzerInitialize(&argc, &argv);
25
22 26 for (int i = 1; i < argc; i++) {
23 27 std::ifstream in(argv[i]);
24 28 in.seekg(0, in.end);
25 29 size_t length = in.tellg();
26 30 in.seekg(0, in.beg);
27 31 std::cout << "Reading " << length << " bytes from " << argv[i]
28 32 << std::endl;
29 33 // Allocate exactly length bytes so that we reliably catch
30 34 // buffer overflows.
31 35 std::vector<char> bytes(length);
32 36 in.read(bytes.data(), bytes.size());
33 37 assert(in);
34 38 LLVMFuzzerTestOneInput(
35 39 reinterpret_cast<const uint8_t *>(bytes.data()),
36 40 bytes.size());
37 41 std::cout << "Execution successful" << std::endl;
38 42 }
39 43 return 0;
40 44 }
41 45 // no-check-code since this is from a third party
General Comments 0
You need to be logged in to leave comments. Login now