bpo-31347: _PyObject_FastCall_Prepend: do not call memcpy if args might not be null (#3329)

Passing NULL as the second argument to to memcpy is undefined behavior even if the size is 0.
This commit is contained in:
Benjamin Peterson 2017-09-04 22:23:42 -07:00 • committed by GitHub
parent db564238db
commit a3070d530c
2 changed files with 4 additions and 3 deletions

View file

@ -0,0 +1 @@
Fix possible undefined behavior in _PyObject_FastCall_Prepend.

View file

@ -854,9 +854,9 @@ _PyObject_FastCall_Prepend(PyObject *callable,
/* use borrowed references */
args2[0] = obj;
memcpy(&args2[1],
args,
(nargs - 1)* sizeof(PyObject *));
if (nargs > 1) {
memcpy(&args2[1], args, (nargs - 1) * sizeof(PyObject *));
}
result = _PyObject_FastCall(callable, args2, nargs);
if (args2 != small_stack) {