summaryrefslogtreecommitdiffstats
path: root/Objects/bytearrayobject.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2015-05-19 18:52:27 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2015-05-19 18:52:27 (GMT)
commit2545411e2848c50bd4f7345fc76e9d24cd063d32 (patch)
tree5d3ee88c71a59a1848382b99cf112e3194a2635b /Objects/bytearrayobject.c
parent637144603621d1aa1a702d925de29c480b9f82e9 (diff)
downloadcpython-2545411e2848c50bd4f7345fc76e9d24cd063d32.zip
cpython-2545411e2848c50bd4f7345fc76e9d24cd063d32.tar.gz
cpython-2545411e2848c50bd4f7345fc76e9d24cd063d32.tar.bz2
Issue #23985: Fix a possible buffer overrun when deleting a slice from the front of a bytearray and then appending some other bytes data.
Patch by Martin Panter.
Diffstat (limited to 'Objects/bytearrayobject.c')
-rw-r--r--Objects/bytearrayobject.c8
1 files changed, 2 insertions, 6 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index f5eb321..8629ab7 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -179,7 +179,7 @@ PyByteArray_Resize(PyObject *self, Py_ssize_t requested_size)
return -1;
}
- if (size + logical_offset + 1 < alloc) {
+ if (size + logical_offset + 1 <= alloc) {
/* Current buffer is large enough to host the requested size,
decide on a strategy. */
if (size < alloc / 2) {
@@ -298,11 +298,7 @@ bytearray_iconcat(PyByteArrayObject *self, PyObject *other)
PyBuffer_Release(&vo);
return PyErr_NoMemory();
}
- if (size < self->ob_alloc) {
- Py_SIZE(self) = size;
- PyByteArray_AS_STRING(self)[Py_SIZE(self)] = '\0'; /* Trailing null byte */
- }
- else if (PyByteArray_Resize((PyObject *)self, size) < 0) {
+ if (PyByteArray_Resize((PyObject *)self, size) < 0) {
PyBuffer_Release(&vo);
return NULL;
}