diff options
author | h1994st <h1994st@gmail.com> | 2020-03-02 19:30:05 -0500 |
---|---|---|
committer | h1994st <h1994st@gmail.com> | 2020-03-02 19:30:05 -0500 |
commit | b2a2b0fc212909df0806abecdd5d64833ae3d3e1 (patch) | |
tree | 4b0b9d017a6be9cb68f8cdf07b7cd7772c496463 /src | |
parent | 7862416844a2636d37754b8b2175dbd97494771f (diff) | |
download | afl++-b2a2b0fc212909df0806abecdd5d64833ae3d3e1.tar.gz |
Add initialization funcation wrapper for Python mutator
Diffstat (limited to 'src')
-rw-r--r-- | src/afl-fuzz-python.c | 34 |
1 files changed, 34 insertions, 0 deletions
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) { |