Show More
@@ -0,0 +1,48 b'' | |||
|
1 | #include <Python.h> | |
|
2 | #include <assert.h> | |
|
3 | #include <stdlib.h> | |
|
4 | #include <unistd.h> | |
|
5 | ||
|
6 | #include <string> | |
|
7 | ||
|
8 | #include "pyutil.h" | |
|
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 parse_dirstate | |
|
19 | try: | |
|
20 | dmap = {} | |
|
21 | copymap = {} | |
|
22 | p = parse_dirstate(dmap, copymap, data) | |
|
23 | except Exception as e: | |
|
24 | pass | |
|
25 | # uncomment this print if you're editing this Python code | |
|
26 | # to debug failures. | |
|
27 | # print e | |
|
28 | )py", | |
|
29 | "fuzzer", Py_file_input); | |
|
30 | return 0; | |
|
31 | } | |
|
32 | ||
|
33 | int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) | |
|
34 | { | |
|
35 | PyObject *text = | |
|
36 | PyBytes_FromStringAndSize((const char *)Data, (Py_ssize_t)Size); | |
|
37 | PyObject *locals = PyDict_New(); | |
|
38 | PyDict_SetItemString(locals, "data", text); | |
|
39 | PyObject *res = PyEval_EvalCode(code, contrib::pyglobals(), locals); | |
|
40 | if (!res) { | |
|
41 | PyErr_Print(); | |
|
42 | } | |
|
43 | Py_XDECREF(res); | |
|
44 | Py_DECREF(locals); | |
|
45 | Py_DECREF(text); | |
|
46 | return 0; // Non-zero return values are reserved for future use. | |
|
47 | } | |
|
48 | } |
@@ -0,0 +1,18 b'' | |||
|
1 | from __future__ import absolute_import, print_function | |
|
2 | ||
|
3 | import argparse | |
|
4 | import os | |
|
5 | import zipfile | |
|
6 | ||
|
7 | ap = argparse.ArgumentParser() | |
|
8 | ap.add_argument("out", metavar="some.zip", type=str, nargs=1) | |
|
9 | args = ap.parse_args() | |
|
10 | ||
|
11 | reporoot = os.path.normpath(os.path.join(os.path.dirname(__file__), | |
|
12 | '..', '..')) | |
|
13 | dirstate = os.path.join(reporoot, '.hg', 'dirstate') | |
|
14 | ||
|
15 | with zipfile.ZipFile(args.out[0], "w", zipfile.ZIP_STORED) as zf: | |
|
16 | if os.path.exists(dirstate): | |
|
17 | with open(dirstate) as f: | |
|
18 | zf.writestr("dirstate", f.read()) |
@@ -135,12 +135,23 b' revlog_fuzzer: sanpy revlog.cc manifest.' | |||
|
135 | 135 | revlog_corpus.zip: |
|
136 | 136 | python revlog_corpus.py $$OUT/revlog_fuzzer_seed_corpus.zip |
|
137 | 137 | |
|
138 | dirstate_fuzzer: sanpy dirstate.cc manifest.o charencode.o parsers.o dirs.o pathencode.o revlog.o pyutil.o | |
|
139 | $(CXX) $(CXXFLAGS) `$$OUT/sanpy/bin/python-config --cflags` \ | |
|
140 | -Wno-register -Wno-macro-redefined \ | |
|
141 | -I../../mercurial dirstate.cc \ | |
|
142 | manifest.o charencode.o parsers.o dirs.o pathencode.o revlog.o pyutil.o \ | |
|
143 | -lFuzzingEngine `$$OUT/sanpy/bin/python-config --ldflags` \ | |
|
144 | -o $$OUT/dirstate_fuzzer | |
|
145 | ||
|
146 | dirstate_corpus.zip: | |
|
147 | python dirstate_corpus.py $$OUT/dirstate_fuzzer_seed_corpus.zip | |
|
148 | ||
|
138 | 149 | clean: |
|
139 | 150 | $(RM) *.o *_fuzzer \ |
|
140 | 151 | bdiff \ |
|
141 | 152 | mpatch \ |
|
142 | 153 | xdiff |
|
143 | 154 | |
|
144 | oss-fuzz: bdiff_fuzzer mpatch_fuzzer mpatch_corpus.zip xdiff_fuzzer manifest_fuzzer manifest_corpus.zip revlog_fuzzer revlog_corpus.zip | |
|
155 | 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 | |
|
145 | 156 | |
|
146 | 157 | .PHONY: all clean oss-fuzz sanpy |
General Comments 0
You need to be logged in to leave comments.
Login now