Debian Codegraph @

Modules/_xxtestfuzz/_xxtestfuzz.c

raw
1 #include <Python.h>
2 #include <stdlib.h>
3 #include <inttypes.h>
4
5 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
6
7 static PyObject* _fuzz_run(PyObject* self, PyObject* args) {
8 const char* buf;
9 Py_ssize_t size;
10 if (!PyArg_ParseTuple(args, "s#", &buf, &size)) {
11 return NULL;
12 }
13 int rv = LLVMFuzzerTestOneInput((const uint8_t*)buf, size);
14 if (PyErr_Occurred()) {
15 return NULL;
16 }
17 if (rv != 0) {
18 // Nonzero return codes are reserved for future use.
19 PyErr_Format(
20 PyExc_RuntimeError, "Nonzero return code from fuzzer: %d", rv);
21 return NULL;
22 }
23 Py_RETURN_NONE;
24 }
25
26 static PyMethodDef module_methods[] = {
27 {"run", _fuzz_run, METH_VARARGS, ""},
28 {NULL},
29 };
30
31 static PyModuleDef_Slot module_slots[] = {
32 {Py_mod_gil, Py_MOD_GIL_NOT_USED},
33 {0, NULL},
34 };
35
36 static struct PyModuleDef _fuzzmodule = {
37 PyModuleDef_HEAD_INIT,
38 "_fuzz",
39 NULL,
40 0,
41 module_methods,
42 module_slots,
43 NULL,
44 NULL,
45 NULL
46 };
47
48 PyMODINIT_FUNC
49 PyInit__xxtestfuzz(void)
50 {
51 return PyModuleDef_Init(&_fuzzmodule);
52 }