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

Gregory P. Smith webhook-mailer at python.org
Fri Jun 7 14:01:59 EDT 2019


https://github.com/python/cpython/commit/1f9531764cc0f8dbca1d8f429d162dc28282f4b4
commit: 1f9531764cc0f8dbca1d8f429d162dc28282f4b4
branch: master
author: Jeroen Demeyer <J.Demeyer at UGent.be>
committer: Gregory P. Smith <greg at krypto.org>
date: 2019年06月07日T11:01:53-07:00
summary:
bpo-37138: fix undefined behaviour with memcpy() on NULL array (GH-13867)
files:
M Objects/classobject.c
diff --git a/Objects/classobject.c b/Objects/classobject.c
index ffd3f875c0e7..2415ed14cb15 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -71,7 +71,11 @@ method_vectorcall(PyObject *method, PyObject *const *args,
 }
 /* use borrowed references */
 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);
 PyMem_Free(newargs);
 }


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /