##// END OF EJS Templates
fuzz: migrate bdiff fuzzer to use FuzzedDataProvider...
Augie Fackler -
r44011:dbc39f02 default
parent child Browse files
Show More
@@ -1,44 +1,42 b''
1 1 /*
2 2 * bdiff.cc - fuzzer harness for bdiff.c
3 3 *
4 4 * Copyright 2018, Google Inc.
5 5 *
6 6 * This software may be used and distributed according to the terms of
7 7 * the GNU General Public License, incorporated herein by reference.
8 8 */
9 9 #include <memory>
10 10 #include <stdlib.h>
11 11
12 #include "fuzzutil.h"
12 #include <fuzzer/FuzzedDataProvider.h>
13 13
14 14 extern "C" {
15 15 #include "bdiff.h"
16 16
17 17 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
18 18 {
19 auto maybe_inputs = SplitInputs(Data, Size);
20 if (!maybe_inputs) {
21 return 0;
22 }
23 auto inputs = std::move(maybe_inputs.value());
19 FuzzedDataProvider provider(Data, Size);
20 std::string left = provider.ConsumeRandomLengthString(Size);
21 std::string right = provider.ConsumeRemainingBytesAsString();
24 22
25 23 struct bdiff_line *a, *b;
26 int an = bdiff_splitlines(inputs.left.get(), inputs.left_size, &a);
27 int bn = bdiff_splitlines(inputs.right.get(), inputs.right_size, &b);
24 int an = bdiff_splitlines(left.c_str(), left.size(), &a);
25 int bn = bdiff_splitlines(right.c_str(), right.size(), &b);
28 26 struct bdiff_hunk l;
29 27 bdiff_diff(a, an, b, bn, &l);
30 28 free(a);
31 29 free(b);
32 30 bdiff_freehunks(l.next);
33 31 return 0; // Non-zero return values are reserved for future use.
34 32 }
35 33
36 34 #ifdef HG_FUZZER_INCLUDE_MAIN
37 35 int main(int argc, char **argv)
38 36 {
39 37 const char data[] = "asdf";
40 38 return LLVMFuzzerTestOneInput((const uint8_t *)data, 4);
41 39 }
42 40 #endif
43 41
44 42 } // extern "C"
General Comments 0
You need to be logged in to leave comments. Login now