author | Yuya Nishihara <yuya@tcha.org> |
Sun, 08 Jul 2018 19:34:11 +0900 | |
changeset 38609 | 980aee54fd70 |
parent 38206 | fa0ddd5e8fff |
child 41140 | 2e60a77b7058 |
permissions | -rw-r--r-- |
36708 | 1 |
/* |
2 |
* xdiff.cc - fuzzer harness for thirdparty/xdiff |
|
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 "thirdparty/xdiff/xdiff.h" |
|
10 |
#include <inttypes.h> |
|
11 |
#include <stdlib.h> |
|
12 |
||
38206
fa0ddd5e8fff
fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
36773
diff
changeset
|
13 |
#include "fuzzutil.h" |
fa0ddd5e8fff
fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
36773
diff
changeset
|
14 |
|
36708 | 15 |
extern "C" { |
16 |
||
17 |
int hunk_consumer(long a1, long a2, long b1, long b2, void *priv) |
|
18 |
{ |
|
19 |
// TODO: probably also test returning -1 from this when things break? |
|
20 |
return 0; |
|
21 |
} |
|
22 |
||
23 |
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) |
|
24 |
{ |
|
38206
fa0ddd5e8fff
fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
36773
diff
changeset
|
25 |
auto maybe_inputs = SplitInputs(Data, Size); |
fa0ddd5e8fff
fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
36773
diff
changeset
|
26 |
if (!maybe_inputs) { |
36708 | 27 |
return 0; |
28 |
} |
|
38206
fa0ddd5e8fff
fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
36773
diff
changeset
|
29 |
auto inputs = std::move(maybe_inputs.value()); |
36708 | 30 |
mmfile_t a, b; |
31 |
||
38206
fa0ddd5e8fff
fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
36773
diff
changeset
|
32 |
a.ptr = inputs.left.get(); |
fa0ddd5e8fff
fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
36773
diff
changeset
|
33 |
a.size = inputs.left_size; |
fa0ddd5e8fff
fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
36773
diff
changeset
|
34 |
b.ptr = inputs.right.get(); |
fa0ddd5e8fff
fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
36773
diff
changeset
|
35 |
b.size = inputs.right_size; |
36708 | 36 |
xpparam_t xpp = { |
37 |
XDF_INDENT_HEURISTIC, /* flags */ |
|
38 |
}; |
|
39 |
xdemitconf_t xecfg = { |
|
40 |
XDL_EMIT_BDIFFHUNK, /* flags */ |
|
41 |
hunk_consumer, /* hunk_consume_func */ |
|
42 |
}; |
|
43 |
xdemitcb_t ecb = { |
|
44 |
NULL, /* priv */ |
|
45 |
}; |
|
46 |
xdl_diff(&a, &b, &xpp, &xecfg, &ecb); |
|
47 |
return 0; // Non-zero return values are reserved for future use. |
|
48 |
} |
|
49 |
||
50 |
#ifdef HG_FUZZER_INCLUDE_MAIN |
|
51 |
int main(int argc, char **argv) |
|
52 |
{ |
|
53 |
const char data[] = "asdf"; |
|
54 |
return LLVMFuzzerTestOneInput((const uint8_t *)data, 4); |
|
55 |
} |
|
56 |
#endif |
|
57 |
||
58 |
} // extern "C" |