about summary refs log tree commit diff
path: root/src/afl-fuzz-python.c
diff options
context:
space:
mode:
authorh1994st <h1994st@gmail.com>2020-03-02 19:30:05 -0500
committerh1994st <h1994st@gmail.com>2020-03-02 19:30:05 -0500
commitb2a2b0fc212909df0806abecdd5d64833ae3d3e1 (patch)
tree4b0b9d017a6be9cb68f8cdf07b7cd7772c496463 /src/afl-fuzz-python.c
parent7862416844a2636d37754b8b2175dbd97494771f (diff)
downloadafl++-b2a2b0fc212909df0806abecdd5d64833ae3d3e1.tar.gz
Add initialization funcation wrapper for Python mutator
Diffstat (limited to 'src/afl-fuzz-python.c')
-rw-r--r--src/afl-fuzz-python.c34
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) {