]> granicus.if.org Git - python/commitdiff
bpo-31347: _PyObject_FastCall_Prepend: do not call memcpy if args might not be null...
authorBenjamin Peterson <benjamin@python.org>
Tue, 5 Sep 2017 05:23:42 +0000 (22:23 -0700)
committerGitHub <noreply@github.com>
Tue, 5 Sep 2017 05:23:42 +0000 (22:23 -0700)
Passing NULL as the second argument to to memcpy is undefined behavior even if the size is 0.

Misc/NEWS.d/next/Core and Builtins/2017-09-04-16-35-06.bpo-31347.KDuf2w.rst [new file with mode: 0644]
Objects/call.c

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 (file)
index 0000000..52a6168
--- /dev/null
@@ -0,0 +1 @@
+Fix possible undefined behavior in _PyObject_FastCall_Prepend.
index 4294a9beb0a9237b5588e529c3a9027d40340e3f..92464327fbc21d05d5b5cb7e5c1c649137ead291 100644 (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) {