[Python-checkins] bpo-31347: _PyObject_FastCall_Prepend: do not call memcpy if args might not be null (#3329)
Benjamin Peterson
webhook-mailer at python.org
Tue Sep 5 01:23:45 EDT 2017
https://github.com/python/cpython/commit/a3070d530c70477273cacbc61660b318582fff44
commit: a3070d530c70477273cacbc61660b318582fff44
branch: master
author: Benjamin Peterson <benjamin at python.org>
committer: GitHub <noreply at github.com>
date: 2017-09-04T22:23:42-07:00
summary:
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.
files:
A Misc/NEWS.d/next/Core and Builtins/2017-09-04-16-35-06.bpo-31347.KDuf2w.rst
M 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
index 00000000000..52a6168e632
--- /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 4294a9beb0a..92464327fbc 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) {
More information about the Python-checkins
mailing list