Skip to content

Commit 1f95317

Browse files
jdemeyergpshead
authored andcommitted
bpo-37138: fix undefined behaviour with memcpy() on NULL array (GH-13867)
1 parent e7e5039 commit 1f95317

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Objects/classobject.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ method_vectorcall(PyObject *method, PyObject *const *args,
7171
}
7272
/* use borrowed references */
7373
newargs[0] = self;
74-
memcpy(newargs + 1, args, totalargs * sizeof(PyObject *));
74+
if (totalargs) { /* bpo-37138: if totalargs == 0, then args may be
75+
* NULL and calling memcpy() with a NULL pointer
76+
* is undefined behaviour. */
77+
memcpy(newargs + 1, args, totalargs * sizeof(PyObject *));
78+
}
7579
result = _PyObject_Vectorcall(func, newargs, nargs+1, kwnames);
7680
PyMem_Free(newargs);
7781
}

0 commit comments

Comments
 (0)