python3.7 support for afl-fuzz py mutator

This commit is contained in:
van Hauser
2019-12-03 10:11:39 +01:00
parent 2b0cfe1ab5
commit 674fbc39f8
6 changed files with 58 additions and 14 deletions

View File

@ -35,7 +35,11 @@ int init_py() {
if (module_name) {
#if PY_MAJOR_VERSION >= 3
PyObject* py_name = PyUnicode_FromString(module_name);
#else
PyObject* py_name = PyString_FromString(module_name);
#endif
py_module = PyImport_Import(py_name);
Py_DECREF(py_name);
@ -91,7 +95,12 @@ int init_py() {
/* Provide the init function a seed for the Python RNG */
py_args = PyTuple_New(1);
#if PY_MAJOR_VERSION >= 3
py_value = PyLong_FromLong(UR(0xFFFFFFFF));
#else
py_value = PyInt_FromLong(UR(0xFFFFFFFF));
#endif
if (!py_value) {
Py_DECREF(py_args);
@ -216,7 +225,11 @@ u32 init_trim_py(char* buf, size_t buflen) {
if (py_value != NULL) {
#if PY_MAJOR_VERSION >= 3
u32 retcnt = (u32) PyLong_AsLong(py_value);
#else
u32 retcnt = PyInt_AsLong(py_value);
#endif
Py_DECREF(py_value);
return retcnt;
@ -250,7 +263,11 @@ u32 post_trim_py(char success) {
if (py_value != NULL) {
#if PY_MAJOR_VERSION >= 3
u32 retcnt = (u32) PyLong_AsLong(py_value);
#else
u32 retcnt = PyInt_AsLong(py_value);
#endif
Py_DECREF(py_value);
return retcnt;