Mercurial > hg
annotate contrib/fuzz/dirstate.cc @ 45066:5a80915e99ce
commitctx: document the manifest writing function
Same spirit as for `_filecommit` lets document the input and output before
making any change or improvement.
This is part of a larger refactoring/cleanup of the commitctx code to clarify
and augment the logic gathering metadata useful for copy tracing. The current
code is a tad too long and entangled to make such update easy. We start with
easy and small cleanup.
Differential Revision: https://phab.mercurial-scm.org/D8705
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 06 Jul 2020 21:08:15 +0200 |
parents | 8766728dbce6 |
children |
rev | line source |
---|---|
41015
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1 #include <Python.h> |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
2 #include <assert.h> |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
3 #include <stdlib.h> |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
4 #include <unistd.h> |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
5 |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
6 #include <string> |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
7 |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
8 #include "pyutil.h" |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
9 |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
10 extern "C" { |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
11 |
43859
8766728dbce6
fuzz: add support for fuzzing under either Python 2 or 3
Augie Fackler <augie@google.com>
parents:
41015
diff
changeset
|
12 static PYCODETYPE *code; |
41015
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
13 |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
14 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
15 { |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
16 contrib::initpy(*argv[0]); |
43859
8766728dbce6
fuzz: add support for fuzzing under either Python 2 or 3
Augie Fackler <augie@google.com>
parents:
41015
diff
changeset
|
17 code = (PYCODETYPE *)Py_CompileString(R"py( |
41015
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
18 try: |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
19 dmap = {} |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
20 copymap = {} |
43859
8766728dbce6
fuzz: add support for fuzzing under either Python 2 or 3
Augie Fackler <augie@google.com>
parents:
41015
diff
changeset
|
21 p = parsers.parse_dirstate(dmap, copymap, data) |
41015
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
22 except Exception as e: |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
23 pass |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
24 # uncomment this print if you're editing this Python code |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
25 # to debug failures. |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
26 # print e |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
27 )py", |
43859
8766728dbce6
fuzz: add support for fuzzing under either Python 2 or 3
Augie Fackler <augie@google.com>
parents:
41015
diff
changeset
|
28 "fuzzer", Py_file_input); |
41015
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
29 return 0; |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
30 } |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
31 |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
32 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
33 { |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
34 PyObject *text = |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
35 PyBytes_FromStringAndSize((const char *)Data, (Py_ssize_t)Size); |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
36 PyObject *locals = PyDict_New(); |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
37 PyDict_SetItemString(locals, "data", text); |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
38 PyObject *res = PyEval_EvalCode(code, contrib::pyglobals(), locals); |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
39 if (!res) { |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
40 PyErr_Print(); |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
41 } |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
42 Py_XDECREF(res); |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
43 Py_DECREF(locals); |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
44 Py_DECREF(text); |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
45 return 0; // Non-zero return values are reserved for future use. |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
46 } |
b444407f635b
fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
47 } |