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