bpo-37138: fix undefined behaviour with memcpy() on NULL array (GH-13867)

This commit is contained in:
Jeroen Demeyer 2019-06-07 20:01:53 +02:00 committed by Gregory P. Smith
parent e7e5039d69
commit 1f9531764c
1 changed files with 5 additions and 1 deletions

View File

@ -71,7 +71,11 @@ method_vectorcall(PyObject *method, PyObject *const *args,
} }
/* use borrowed references */ /* use borrowed references */
newargs[0] = self; newargs[0] = self;
memcpy(newargs + 1, args, totalargs * sizeof(PyObject *)); if (totalargs) { /* bpo-37138: if totalargs == 0, then args may be
* NULL and calling memcpy() with a NULL pointer
* is undefined behaviour. */
memcpy(newargs + 1, args, totalargs * sizeof(PyObject *));
}
result = _PyObject_Vectorcall(func, newargs, nargs+1, kwnames); result = _PyObject_Vectorcall(func, newargs, nargs+1, kwnames);
PyMem_Free(newargs); PyMem_Free(newargs);
} }