##// END OF EJS Templates
fuzz: fix xdiff build...
Jun Wu -
r36783:04d64163 default
parent child Browse files
Show More
@@ -1,40 +1,40
1 1 bdiff.o: ../../mercurial/bdiff.c
2 2 clang -g -O1 -fsanitize=fuzzer-no-link,address -c -o bdiff.o \
3 3 ../../mercurial/bdiff.c
4 4
5 5 bdiff: bdiff.cc bdiff.o
6 6 clang -DHG_FUZZER_INCLUDE_MAIN=1 -g -O1 -fsanitize=fuzzer-no-link,address \
7 7 -I../../mercurial bdiff.cc bdiff.o -o bdiff
8 8
9 9 bdiff-oss-fuzz.o: ../../mercurial/bdiff.c
10 10 $$CC $$CFLAGS -c -o bdiff-oss-fuzz.o ../../mercurial/bdiff.c
11 11
12 12 bdiff_fuzzer: bdiff.cc bdiff-oss-fuzz.o
13 13 $$CXX $$CXXFLAGS -std=c++11 -I../../mercurial bdiff.cc \
14 14 bdiff-oss-fuzz.o -lFuzzingEngine -o $$OUT/bdiff_fuzzer
15 15
16 16 x%.o: ../../mercurial/thirdparty/xdiff/x%.c ../../mercurial/thirdparty/xdiff/*.h
17 17 clang -g -O1 -fsanitize=fuzzer-no-link,address -c \
18 18 -o $@ \
19 19 $<
20 20
21 xdiff: xdiff.cc xdiffi.o xemit.o xmerge.o xprepare.o xutils.o
21 xdiff: xdiff.cc xdiffi.o xprepare.o xutils.o
22 22 clang -DHG_FUZZER_INCLUDE_MAIN=1 -g -O1 -fsanitize=fuzzer-no-link,address \
23 23 -I../../mercurial xdiff.cc \
24 xdiffi.o xemit.o xmerge.o xprepare.o xutils.o -o xdiff
24 xdiffi.o xprepare.o xutils.o -o xdiff
25 25
26 26 fuzz-x%.o: ../../mercurial/thirdparty/xdiff/x%.c ../../mercurial/thirdparty/xdiff/*.h
27 27 $$CC $$CFLAGS -c \
28 28 -o $@ \
29 29 $<
30 30
31 xdiff_fuzzer: xdiff.cc fuzz-xdiffi.o fuzz-xemit.o fuzz-xmerge.o fuzz-xprepare.o fuzz-xutils.o
31 xdiff_fuzzer: xdiff.cc fuzz-xdiffi.o fuzz-xprepare.o fuzz-xutils.o
32 32 $$CXX $$CXXFLAGS -std=c++11 -I../../mercurial xdiff.cc \
33 fuzz-xdiffi.o fuzz-xemit.o fuzz-xmerge.o fuzz-xprepare.o fuzz-xutils.o \
33 fuzz-xdiffi.o fuzz-xprepare.o fuzz-xutils.o \
34 34 -lFuzzingEngine -o $$OUT/xdiff_fuzzer
35 35
36 36 all: bdiff xdiff
37 37
38 38 oss-fuzz: bdiff_fuzzer xdiff_fuzzer
39 39
40 40 .PHONY: all oss-fuzz
@@ -1,67 +1,60
1 1 /*
2 2 * xdiff.cc - fuzzer harness for thirdparty/xdiff
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 "thirdparty/xdiff/xdiff.h"
10 10 #include <inttypes.h>
11 11 #include <stdlib.h>
12 12
13 13 extern "C" {
14 14
15 15 int hunk_consumer(long a1, long a2, long b1, long b2, void *priv)
16 16 {
17 17 // TODO: probably also test returning -1 from this when things break?
18 18 return 0;
19 19 }
20 20
21 21 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
22 22 {
23 23 if (!Size) {
24 24 return 0;
25 25 }
26 26 // figure out a random point in [0, Size] to split our input.
27 27 size_t split = Data[0] / 255.0 * Size;
28 28
29 29 mmfile_t a, b;
30 30
31 31 // `a` input to diff is data[1:split]
32 32 a.ptr = (char *)Data + 1;
33 33 // which has len split-1
34 34 a.size = split - 1;
35 35 // `b` starts at the next byte after `a` ends
36 36 b.ptr = a.ptr + a.size;
37 37 b.size = Size - split;
38 38 xpparam_t xpp = {
39 39 XDF_INDENT_HEURISTIC, /* flags */
40 NULL, /* anchors */
41 0, /* anchors_nr */
42 40 };
43 41 xdemitconf_t xecfg = {
44 0, /* ctxlen */
45 0, /* interhunkctxlen */
46 42 XDL_EMIT_BDIFFHUNK, /* flags */
47 NULL, /* find_func */
48 NULL, /* find_func_priv */
49 43 hunk_consumer, /* hunk_consume_func */
50 44 };
51 45 xdemitcb_t ecb = {
52 46 NULL, /* priv */
53 NULL, /* outf */
54 47 };
55 48 xdl_diff(&a, &b, &xpp, &xecfg, &ecb);
56 49 return 0; // Non-zero return values are reserved for future use.
57 50 }
58 51
59 52 #ifdef HG_FUZZER_INCLUDE_MAIN
60 53 int main(int argc, char **argv)
61 54 {
62 55 const char data[] = "asdf";
63 56 return LLVMFuzzerTestOneInput((const uint8_t *)data, 4);
64 57 }
65 58 #endif
66 59
67 60 } // extern "C"
General Comments 0
You need to be logged in to leave comments. Login now