Commit ff8a6039 authored by Orivej Desh's avatar Orivej Desh

Fix calling va_arg function with a NULL argument from generated C++ code

C++ allows NULL to be a literal 0 [1], and this actually happens on some Linux
systems when linux/stddef.h happens to be included [2]. When 0 is passed to a
variadic function as a 7th or later argument, it is passed on the stack, and
Clang encodes this on AMD64 with "mov dword ptr [rsp], 0" because it is an
int. This sets lower 32 bits to zero, but leaves upper 32 bits unchanged.
When they happen to be non zero, the called function that expects the last
argument to be a zero pointer reads past the last intended argument and
eventually segfaults.

[1] https://en.cppreference.com/w/cpp/types/NULL
[2] https://stackoverflow.com/a/31285400/1687334
[3] https://godbolt.org/g/o4Av7Q
parent 83bf24e7
......@@ -65,7 +65,7 @@ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
if (!py_level)
goto bad;
module = PyObject_CallFunctionObjArgs(py_import,
name, global_dict, empty_dict, list, py_level, NULL);
name, global_dict, empty_dict, list, py_level, (PyObject *)NULL);
Py_DECREF(py_level);
#else
module = PyImport_ImportModuleLevelObject(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment