diff options
author | Martin Panter <vadmium+py@gmail.com> | 2015-11-07 02:32:21 +0000 |
---|---|---|
committer | Martin Panter <vadmium+py@gmail.com> | 2015-11-07 02:32:21 +0000 |
commit | eeb896c4116dd763efea45cb3c1b53257128f4e4 (patch) | |
tree | 34e8df45212ee5c99849dfca30977b92901615d6 /Objects/floatobject.c | |
parent | 9ad0aae6566311c6982a20955381cda5a2954519 (diff) | |
download | cpython-git-eeb896c4116dd763efea45cb3c1b53257128f4e4.tar.gz |
Issue #24802: Copy bytes-like objects to null-terminated buffers if necessary
This avoids possible buffer overreads when int(), float(), compile(), exec()
and eval() are passed bytes-like objects. Similar code is removed from the
complex() constructor, where it was not reachable.
Patch by John Leitch, Serhiy Storchaka and Martin Panter.
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r-- | Objects/floatobject.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 1dca947906..9c1b714af3 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -144,9 +144,24 @@ PyFloat_FromString(PyObject *v) return NULL; } } + else if (PyBytes_Check(v)) { + s = PyBytes_AS_STRING(v); + len = PyBytes_GET_SIZE(v); + } + else if (PyByteArray_Check(v)) { + s = PyByteArray_AS_STRING(v); + len = PyByteArray_GET_SIZE(v); + } else if (PyObject_GetBuffer(v, &view, PyBUF_SIMPLE) == 0) { s = (const char *)view.buf; len = view.len; + /* Copy to NUL-terminated buffer. */ + s_buffer = PyBytes_FromStringAndSize(s, len); + if (s_buffer == NULL) { + PyBuffer_Release(&view); + return NULL; + } + s = PyBytes_AS_STRING(s_buffer); } else { PyErr_Format(PyExc_TypeError, |