2017-09-06 15:15:35 -03:00
|
|
|
#include <Python.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
|
|
|
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
|
|
|
|
|
|
|
|
static PyObject* _fuzz_run(PyObject* self, PyObject* args) {
|
|
|
|
const char* buf;
|
|
|
|
Py_ssize_t size;
|
|
|
|
if (!PyArg_ParseTuple(args, "s#", &buf, &size)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
int rv = LLVMFuzzerTestOneInput((const uint8_t*)buf, size);
|
|
|
|
if (PyErr_Occurred()) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (rv != 0) {
|
|
|
|
// Nonzero return codes are reserved for future use.
|
|
|
|
PyErr_Format(
|
|
|
|
PyExc_RuntimeError, "Nonzero return code from fuzzer: %d", rv);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyMethodDef module_methods[] = {
|
|
|
|
{"run", (PyCFunction)_fuzz_run, METH_VARARGS, ""},
|
|
|
|
{NULL},
|
|
|
|
};
|
|
|
|
|
2024-05-03 12:30:55 -03:00
|
|
|
static PyModuleDef_Slot module_slots[] = {
|
|
|
|
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
|
|
|
|
{0, NULL},
|
|
|
|
};
|
|
|
|
|
2017-09-06 15:15:35 -03:00
|
|
|
static struct PyModuleDef _fuzzmodule = {
|
|
|
|
PyModuleDef_HEAD_INIT,
|
|
|
|
"_fuzz",
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
module_methods,
|
2024-05-03 12:30:55 -03:00
|
|
|
module_slots,
|
2017-09-06 15:15:35 -03:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
PyMODINIT_FUNC
|
|
|
|
PyInit__xxtestfuzz(void)
|
|
|
|
{
|
2024-05-03 12:30:55 -03:00
|
|
|
return PyModuleDef_Init(&_fuzzmodule);
|
2017-09-06 15:15:35 -03:00
|
|
|
}
|