Show More
@@ -0,0 +1,56 b'' | |||||
|
1 | #include <Python.h> | |||
|
2 | #include <assert.h> | |||
|
3 | #include <stdlib.h> | |||
|
4 | #include <unistd.h> | |||
|
5 | ||||
|
6 | #include "pyutil.h" | |||
|
7 | ||||
|
8 | #include <string> | |||
|
9 | ||||
|
10 | extern "C" { | |||
|
11 | ||||
|
12 | static PyCodeObject *code; | |||
|
13 | ||||
|
14 | extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) | |||
|
15 | { | |||
|
16 | contrib::initpy(*argv[0]); | |||
|
17 | code = (PyCodeObject *)Py_CompileString(R"py( | |||
|
18 | from parsers import dirs | |||
|
19 | try: | |||
|
20 | files = mdata.split('\n') | |||
|
21 | d = dirs(files) | |||
|
22 | list(d) | |||
|
23 | 'a' in d | |||
|
24 | if files: | |||
|
25 | files[0] in d | |||
|
26 | except Exception as e: | |||
|
27 | pass | |||
|
28 | # uncomment this print if you're editing this Python code | |||
|
29 | # to debug failures. | |||
|
30 | # print e | |||
|
31 | )py", | |||
|
32 | "fuzzer", Py_file_input); | |||
|
33 | return 0; | |||
|
34 | } | |||
|
35 | ||||
|
36 | int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) | |||
|
37 | { | |||
|
38 | // Don't allow fuzzer inputs larger than 100k, since we'll just bog | |||
|
39 | // down and not accomplish much. | |||
|
40 | if (Size > 100000) { | |||
|
41 | return 0; | |||
|
42 | } | |||
|
43 | PyObject *mtext = | |||
|
44 | PyBytes_FromStringAndSize((const char *)Data, (Py_ssize_t)Size); | |||
|
45 | PyObject *locals = PyDict_New(); | |||
|
46 | PyDict_SetItemString(locals, "mdata", mtext); | |||
|
47 | PyObject *res = PyEval_EvalCode(code, contrib::pyglobals(), locals); | |||
|
48 | if (!res) { | |||
|
49 | PyErr_Print(); | |||
|
50 | } | |||
|
51 | Py_XDECREF(res); | |||
|
52 | Py_DECREF(locals); | |||
|
53 | Py_DECREF(mtext); | |||
|
54 | return 0; // Non-zero return values are reserved for future use. | |||
|
55 | } | |||
|
56 | } |
@@ -105,6 +105,17 b' revlog.o: ../../mercurial/cext/revlog.c' | |||||
105 | -I../../mercurial \ |
|
105 | -I../../mercurial \ | |
106 | -c -o revlog.o ../../mercurial/cext/revlog.c |
|
106 | -c -o revlog.o ../../mercurial/cext/revlog.c | |
107 |
|
107 | |||
|
108 | dirs_fuzzer: dirs.cc manifest.o charencode.o parsers.o dirs.o pathencode.o revlog.o pyutil.o | |||
|
109 | $(CXX) $(CXXFLAGS) `$$OUT/sanpy/bin/python-config --cflags` \ | |||
|
110 | -Wno-register -Wno-macro-redefined \ | |||
|
111 | -I../../mercurial dirs.cc \ | |||
|
112 | manifest.o charencode.o parsers.o dirs.o pathencode.o revlog.o pyutil.o \ | |||
|
113 | -lFuzzingEngine `$$OUT/sanpy/bin/python-config --ldflags` \ | |||
|
114 | -o $$OUT/dirs_fuzzer | |||
|
115 | ||||
|
116 | manifest_corpus.zip: | |||
|
117 | python manifest_corpus.py $$OUT/manifest_fuzzer_seed_corpus.zip | |||
|
118 | ||||
108 | manifest_fuzzer: manifest.cc manifest.o charencode.o parsers.o dirs.o pathencode.o revlog.o pyutil.o |
|
119 | manifest_fuzzer: manifest.cc manifest.o charencode.o parsers.o dirs.o pathencode.o revlog.o pyutil.o | |
109 | $(CXX) $(CXXFLAGS) `$$OUT/sanpy/bin/python-config --cflags` \ |
|
120 | $(CXX) $(CXXFLAGS) `$$OUT/sanpy/bin/python-config --cflags` \ | |
110 | -Wno-register -Wno-macro-redefined \ |
|
121 | -Wno-register -Wno-macro-redefined \ | |
@@ -113,9 +124,6 b' manifest_fuzzer: manifest.cc manifest.o ' | |||||
113 | -lFuzzingEngine `$$OUT/sanpy/bin/python-config --ldflags` \ |
|
124 | -lFuzzingEngine `$$OUT/sanpy/bin/python-config --ldflags` \ | |
114 | -o $$OUT/manifest_fuzzer |
|
125 | -o $$OUT/manifest_fuzzer | |
115 |
|
126 | |||
116 | manifest_corpus.zip: |
|
|||
117 | python manifest_corpus.py $$OUT/manifest_fuzzer_seed_corpus.zip |
|
|||
118 |
|
||||
119 | revlog_fuzzer: revlog.cc manifest.o charencode.o parsers.o dirs.o pathencode.o revlog.o pyutil.o |
|
127 | revlog_fuzzer: revlog.cc manifest.o charencode.o parsers.o dirs.o pathencode.o revlog.o pyutil.o | |
120 | $(CXX) $(CXXFLAGS) `$$OUT/sanpy/bin/python-config --cflags` \ |
|
128 | $(CXX) $(CXXFLAGS) `$$OUT/sanpy/bin/python-config --cflags` \ | |
121 | -Wno-register -Wno-macro-redefined \ |
|
129 | -Wno-register -Wno-macro-redefined \ | |
@@ -155,6 +163,6 b' clean:' | |||||
155 | mpatch \ |
|
163 | mpatch \ | |
156 | xdiff |
|
164 | xdiff | |
157 |
|
165 | |||
158 | oss-fuzz: bdiff_fuzzer mpatch_fuzzer mpatch_corpus.zip xdiff_fuzzer manifest_fuzzer manifest_corpus.zip revlog_fuzzer revlog_corpus.zip dirstate_fuzzer dirstate_corpus.zip fm1readmarkers_fuzzer fm1readmarkers_corpus.zip |
|
166 | oss-fuzz: bdiff_fuzzer mpatch_fuzzer mpatch_corpus.zip xdiff_fuzzer dirs_fuzzer manifest_fuzzer manifest_corpus.zip revlog_fuzzer revlog_corpus.zip dirstate_fuzzer dirstate_corpus.zip fm1readmarkers_fuzzer fm1readmarkers_corpus.zip | |
159 |
|
167 | |||
160 | .PHONY: all clean oss-fuzz |
|
168 | .PHONY: all clean oss-fuzz |
General Comments 0
You need to be logged in to leave comments.
Login now