cpython: d465da1e5902 (original) (raw)

Mercurial > cpython

changeset 103290:d465da1e5902 2.7

Issue #27570: Avoid zero-length memcpy() calls with null source pointers [#27570]

Martin Panter vadmium+py@gmail.com
date Wed, 07 Sep 2016 11:04:41 +0000
parents 731e5617cc8d
children 9a68ab141c33
files Lib/test/test_array.py Misc/NEWS Modules/_ctypes/_ctypes.c Modules/_ctypes/stgdict.c Modules/arraymodule.c
diffstat 5 files changed, 42 insertions(+), 15 deletions(-)[+] [-] Lib/test/test_array.py 16 Misc/NEWS 3 Modules/_ctypes/_ctypes.c 6 Modules/_ctypes/stgdict.c 8 Modules/arraymodule.c 24

line wrap: on

line diff

--- a/Lib/test/test_array.py +++ b/Lib/test/test_array.py @@ -22,9 +22,9 @@ typecodes = "cbBhHiIlLfd" if test_support.have_unicode: typecodes += "u" -class BadConstructorTest(unittest.TestCase): +class MiscTest(unittest.TestCase):

@@ -40,7 +40,17 @@ class BadConstructorTest(unittest.TestCa self.assertRaises(ValueError, array.array, u'x') self.assertRaises(ValueError, array.array, u'\x80') -tests.append(BadConstructorTest)

+ +tests.append(MiscTest) class BaseTest(unittest.TestCase): # Required class attributes (provided by subclasses

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -40,6 +40,9 @@ Core and Builtins Library ------- +- Issue #27570: Avoid zero-length memcpy() etc calls with null source

--- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -1426,8 +1426,10 @@ PyCArrayType_new(PyTypeObject *type, PyO return NULL; } stgdict->shape[0] = length;

itemsize = itemdict->size; if (length * itemsize < 0) {

--- a/Modules/_ctypes/stgdict.c +++ b/Modules/_ctypes/stgdict.c @@ -395,9 +395,11 @@ PyCStructUnionType_update_stgdict(PyObje } memset(stgdict->ffi_type_pointer.elements, 0, sizeof(ffi_type *) * (basedict->length + len + 1));

--- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -620,8 +620,10 @@ array_slice(arrayobject *a, Py_ssize_t i np = (arrayobject *) newarrayobject(&Arraytype, ihigh - ilow, a->ob_descr); if (np == NULL) return NULL;

@@ -660,9 +662,13 @@ array_concat(arrayobject *a, PyObject *b if (np == NULL) { return NULL; }

#undef b } @@ -684,6 +690,8 @@ array_repeat(arrayobject *a, Py_ssize_t np = (arrayobject *) newarrayobject(&Arraytype, size, a->ob_descr); if (np == NULL) return NULL;