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