diff options
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_io/iobase.c | 13 | ||||
-rw-r--r-- | Modules/cjkcodecs/multibytecodec.c | 3 | ||||
-rw-r--r-- | Modules/posixmodule.c | 5 |
3 files changed, 16 insertions, 5 deletions
diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c index 066dc8e..d813daf 100644 --- a/Modules/_io/iobase.c +++ b/Modules/_io/iobase.c @@ -571,7 +571,8 @@ iobase_iternext(PyObject *self) if (line == NULL) return NULL; - if (PyObject_Size(line) == 0) { + if (PyObject_Size(line) <= 0) { + /* Error or empty */ Py_DECREF(line); return NULL; } @@ -618,6 +619,7 @@ iobase_readlines(PyObject *self, PyObject *args) } while (1) { + Py_ssize_t line_length; PyObject *line = PyIter_Next(it); if (line == NULL) { if (PyErr_Occurred()) { @@ -631,11 +633,14 @@ iobase_readlines(PyObject *self, PyObject *args) Py_DECREF(line); goto error; } - length += PyObject_Size(line); + line_length = PyObject_Size(line); Py_DECREF(line); - - if (length > hint) + if (line_length < 0) { + goto error; + } + if (line_length > hint - length) break; + length += line_length; } Py_DECREF(it); diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c index 8713628..8901b42 100644 --- a/Modules/cjkcodecs/multibytecodec.c +++ b/Modules/cjkcodecs/multibytecodec.c @@ -1604,6 +1604,9 @@ mbstreamwriter_writelines(MultibyteStreamWriterObject *self, PyObject *lines) if (r == -1) return NULL; } + /* PySequence_Length() can fail */ + if (PyErr_Occurred()) + return NULL; Py_RETURN_NONE; } diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index e73805f..ad50536 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -6077,7 +6077,7 @@ Set the groups of the current process to list."); static PyObject * posix_setgroups(PyObject *self, PyObject *groups) { - int i, len; + Py_ssize_t i, len; gid_t grouplist[MAX_GROUPS]; if (!PySequence_Check(groups)) { @@ -6085,6 +6085,9 @@ posix_setgroups(PyObject *self, PyObject *groups) return NULL; } len = PySequence_Size(groups); + if (len < 0) { + return NULL; + } if (len > MAX_GROUPS) { PyErr_SetString(PyExc_ValueError, "too many groups"); return NULL; |