summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-06-29 18:13:54 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-06-29 18:13:54 (GMT)
commitab766350b665ff2cafb92191a7cd720a1ebf6fe7 (patch)
tree3aa9a213d1fc8433558ac2861b491337555024e5 /Objects
parenteabfe8cc0e061081d1cbcef4895a99cf7520e8d1 (diff)
downloadcpython-ab766350b665ff2cafb92191a7cd720a1ebf6fe7.zip
cpython-ab766350b665ff2cafb92191a7cd720a1ebf6fe7.tar.gz
cpython-ab766350b665ff2cafb92191a7cd720a1ebf6fe7.tar.bz2
Issue #24467: Fixed possible buffer over-read in bytearray. The bytearray
object now always allocates place for trailing null byte and it's buffer now is always null-terminated.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/bytearrayobject.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 5f57580..5276da5 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -897,8 +897,10 @@ bytearray_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
goto error;
/* Append the byte */
- if (Py_SIZE(self) < self->ob_alloc)
+ if (Py_SIZE(self) + 1 < self->ob_alloc) {
Py_SIZE(self)++;
+ PyByteArray_AS_STRING(self)[Py_SIZE(self)] = '\0';
+ }
else if (PyByteArray_Resize((PyObject *)self, Py_SIZE(self)+1) < 0)
goto error;
self->ob_bytes[Py_SIZE(self)-1] = value;