From b2a2b0fc212909df0806abecdd5d64833ae3d3e1 Mon Sep 17 00:00:00 2001 From: h1994st Date: Mon, 2 Mar 2020 19:30:05 -0500 Subject: Add initialization funcation wrapper for Python mutator --- src/afl-fuzz-python.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/afl-fuzz-python.c') diff --git a/src/afl-fuzz-python.c b/src/afl-fuzz-python.c index da478cc2..30156fa6 100644 --- a/src/afl-fuzz-python.c +++ b/src/afl-fuzz-python.c @@ -118,6 +118,40 @@ void finalize_py_module() { } +void init_py(unsigned int seed) { + PyObject *py_args, *py_value; + + /* Provide the init function a seed for the Python RNG */ + py_args = PyTuple_New(1); +#if PY_MAJOR_VERSION >= 3 + py_value = PyLong_FromLong(seed); +#else + py_value = PyInt_FromLong(seed); +#endif + + if (!py_value) { + + Py_DECREF(py_args); + fprintf(stderr, "Cannot convert argument\n"); + return; + + } + + PyTuple_SetItem(py_args, 0, py_value); + + py_value = PyObject_CallObject(py_functions[PY_FUNC_INIT], py_args); + + Py_DECREF(py_args); + + if (py_value == NULL) { + + PyErr_Print(); + fprintf(stderr, "Call failed\n"); + return; + + } +} + void fuzz_py(char* buf, size_t buflen, char* add_buf, size_t add_buflen, char** ret, size_t* retlen) { -- cgit 1.4.1