1 /*
2 * bdiff.cc - fuzzer harness for bdiff.c
3 *
4 * Copyright 2018, Google Inc.
5 *
6 * This software may be used and distributed according to the terms of
7 * the GNU General Public License, incorporated herein by reference.
8 */
9 #include <memory>
10 #include <stdlib.h>
11
12 #include "FuzzedDataProvider.h"
13
14 extern "C" {
15 #include "bdiff.h"
16
LLVMFuzzerInitialize(int * argc,char *** argv)17 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
18 {
19 return 0;
20 }
21
LLVMFuzzerTestOneInput(const uint8_t * Data,size_t Size)22 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
23 {
24 FuzzedDataProvider provider(Data, Size);
25 std::string left = provider.ConsumeRandomLengthString(Size);
26 std::string right = provider.ConsumeRemainingBytesAsString();
27
28 struct bdiff_line *a, *b;
29 int an = bdiff_splitlines(left.c_str(), left.size(), &a);
30 int bn = bdiff_splitlines(right.c_str(), right.size(), &b);
31 struct bdiff_hunk l;
32 bdiff_diff(a, an, b, bn, &l);
33 free(a);
34 free(b);
35 bdiff_freehunks(l.next);
36 return 0; // Non-zero return values are reserved for future use.
37 }
38
39 } // extern "C"
40