diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-06-29 18:18:01 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-06-29 18:18:01 (GMT) |
commit | bc9e75ed023ff03f555682e57d25fee32e6548a0 (patch) | |
tree | 5f31459160ab9cae7a005ce01766d834f321e26d /Objects/bytearrayobject.c | |
parent | a95a476b3ae93d890209e592d675ae64c82e05dc (diff) | |
parent | 7b6e3b91f54e8fafbb1565a7d0999dec4fca783f (diff) | |
download | cpython-bc9e75ed023ff03f555682e57d25fee32e6548a0.zip cpython-bc9e75ed023ff03f555682e57d25fee32e6548a0.tar.gz cpython-bc9e75ed023ff03f555682e57d25fee32e6548a0.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/bytearrayobject.c')
-rw-r--r-- | Objects/bytearrayobject.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index 49db367..dae80d9 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -891,8 +891,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; PyByteArray_AS_STRING(self)[Py_SIZE(self)-1] = value; |