summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-09-07 11:04:41 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-09-07 11:04:41 (GMT)
commitbe8da9c9906571698fe218da9e218ece500d5239 (patch)
tree266a4c850eecabfe37873825cd5414c034e98769 /Modules
parent799520c91ef6f2d1016e1f05790779a9cb7624d9 (diff)
downloadcpython-be8da9c9906571698fe218da9e218ece500d5239.zip
cpython-be8da9c9906571698fe218da9e218ece500d5239.tar.gz
cpython-be8da9c9906571698fe218da9e218ece500d5239.tar.bz2
Issue #27570: Avoid zero-length memcpy() calls with null source pointers
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ctypes/_ctypes.c6
-rw-r--r--Modules/_ctypes/stgdict.c8
-rw-r--r--Modules/arraymodule.c24
3 files changed, 25 insertions, 13 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index b20039f..7de9cee 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -1381,8 +1381,10 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
goto error;
}
stgdict->shape[0] = length;
- memmove(&stgdict->shape[1], itemdict->shape,
- sizeof(Py_ssize_t) * (stgdict->ndim - 1));
+ if (stgdict->ndim > 1) {
+ memmove(&stgdict->shape[1], itemdict->shape,
+ sizeof(Py_ssize_t) * (stgdict->ndim - 1));
+ }
itemsize = itemdict->size;
if (length * itemsize < 0) {
diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c
index 879afb8..6c0fda9 100644
--- a/Modules/_ctypes/stgdict.c
+++ b/Modules/_ctypes/stgdict.c
@@ -391,9 +391,11 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
}
memset(stgdict->ffi_type_pointer.elements, 0,
sizeof(ffi_type *) * (basedict->length + len + 1));
- memcpy(stgdict->ffi_type_pointer.elements,
- basedict->ffi_type_pointer.elements,
- sizeof(ffi_type *) * (basedict->length));
+ if (basedict->length > 0) {
+ memcpy(stgdict->ffi_type_pointer.elements,
+ basedict->ffi_type_pointer.elements,
+ sizeof(ffi_type *) * (basedict->length));
+ }
ffi_ofs = basedict->length;
} else {
offset = 0;
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index b9f87ae..a4966b4 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -745,8 +745,10 @@ array_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh)
np = (arrayobject *) newarrayobject(&Arraytype, ihigh - ilow, a->ob_descr);
if (np == NULL)
return NULL;
- memcpy(np->ob_item, a->ob_item + ilow * a->ob_descr->itemsize,
- (ihigh-ilow) * a->ob_descr->itemsize);
+ if (ihigh > ilow) {
+ memcpy(np->ob_item, a->ob_item + ilow * a->ob_descr->itemsize,
+ (ihigh-ilow) * a->ob_descr->itemsize);
+ }
return (PyObject *)np;
}
@@ -804,9 +806,13 @@ array_concat(arrayobject *a, PyObject *bb)
if (np == NULL) {
return NULL;
}
- memcpy(np->ob_item, a->ob_item, Py_SIZE(a)*a->ob_descr->itemsize);
- memcpy(np->ob_item + Py_SIZE(a)*a->ob_descr->itemsize,
- b->ob_item, Py_SIZE(b)*b->ob_descr->itemsize);
+ if (Py_SIZE(a) > 0) {
+ memcpy(np->ob_item, a->ob_item, Py_SIZE(a)*a->ob_descr->itemsize);
+ }
+ if (Py_SIZE(b) > 0) {
+ memcpy(np->ob_item + Py_SIZE(a)*a->ob_descr->itemsize,
+ b->ob_item, Py_SIZE(b)*b->ob_descr->itemsize);
+ }
return (PyObject *)np;
#undef b
}
@@ -826,7 +832,7 @@ array_repeat(arrayobject *a, Py_ssize_t n)
np = (arrayobject *) newarrayobject(&Arraytype, size, a->ob_descr);
if (np == NULL)
return NULL;
- if (n == 0)
+ if (size == 0)
return (PyObject *)np;
oldbytes = Py_SIZE(a) * a->ob_descr->itemsize;
newbytes = oldbytes * n;
@@ -985,8 +991,10 @@ array_do_extend(arrayobject *self, PyObject *bb)
size = oldsize + Py_SIZE(b);
if (array_resize(self, size) == -1)
return -1;
- memcpy(self->ob_item + oldsize * self->ob_descr->itemsize,
- b->ob_item, bbsize * b->ob_descr->itemsize);
+ if (bbsize > 0) {
+ memcpy(self->ob_item + oldsize * self->ob_descr->itemsize,
+ b->ob_item, bbsize * b->ob_descr->itemsize);
+ }
return 0;
#undef b