From: Benjamin Peterson Date: Tue, 5 Sep 2017 05:23:42 +0000 (-0700) Subject: bpo-31347: _PyObject_FastCall_Prepend: do not call memcpy if args might not be null... X-Git-Tag: v3.7.0a1~155 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a3070d530c70477273cacbc61660b318582fff44;p=python 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. --- diff --git a/Misc/NEWS.d/next/Core and Builtins/2017-09-04-16-35-06.bpo-31347.KDuf2w.rst b/Misc/NEWS.d/next/Core and Builtins/2017-09-04-16-35-06.bpo-31347.KDuf2w.rst new file mode 100644 index 0000000000..52a6168e63 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2017-09-04-16-35-06.bpo-31347.KDuf2w.rst @@ -0,0 +1 @@ +Fix possible undefined behavior in _PyObject_FastCall_Prepend. diff --git a/Objects/call.c b/Objects/call.c index 4294a9beb0..92464327fb 100644 --- a/Objects/call.c +++ b/Objects/call.c @@ -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) {