Browse Source

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

(cherry picked from commit 1f9531764c)

Co-authored-by: Jeroen Demeyer <J.Demeyer@UGent.be>
pull/13901/head
Miss Islington (bot) 7 years ago
committed by GitHub
parent
commit
6e053079ac
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      Objects/classobject.c

6
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);
}

Loading…
Cancel
Save