diff options
author | stratakis <cstratak@redhat.com> | 2020-07-08 20:39:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-08 20:39:41 (GMT) |
commit | 61fc23ca106bc82955b0e59d1ab42285b94899e2 (patch) | |
tree | 0e51e0ad6ba717d354fb1db36c8668e292759dab /Objects/bytearrayobject.c | |
parent | 529f42645d38b6b0075f256814dfb3d220ac7d92 (diff) | |
download | cpython-61fc23ca106bc82955b0e59d1ab42285b94899e2.zip cpython-61fc23ca106bc82955b0e59d1ab42285b94899e2.tar.gz cpython-61fc23ca106bc82955b0e59d1ab42285b94899e2.tar.bz2 |
bpo-41175: Guard against a NULL pointer dereference within bytearrayobject (GH-21240)
The issue is triggered by the bytearray() + bytearray() operation.
Detected by GCC 10 static analysis tool.
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 83c79b2..7035061 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -266,7 +266,9 @@ PyByteArray_Concat(PyObject *a, PyObject *b) result = (PyByteArrayObject *) \ PyByteArray_FromStringAndSize(NULL, va.len + vb.len); - if (result != NULL) { + // result->ob_bytes is NULL if result is an empty string: + // if va.len + vb.len equals zero. + if (result != NULL && result->ob_bytes != NULL) { memcpy(result->ob_bytes, va.buf, va.len); memcpy(result->ob_bytes + va.len, vb.buf, vb.len); } |