From: Michael W. Hudson Date: Mon, 26 Sep 2005 13:15:34 +0000 (+0000) Subject: Backport (with Anthony's blessing (in fact he reminded me to do it :)): X-Git-Tag: v2.4.2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ea2ef08e833524a58527e63499eacc2f64544499;p=thirdparty%2FPython%2Fcpython.git Backport (with Anthony's blessing (in fact he reminded me to do it :)): Patches #1298449 and #1298499: Add some missing checks for error returns in cStringIO.c. Thanks to Andrew Bennetts. This must be a backport candidate. --- diff --git a/Lib/test/test_StringIO.py b/Lib/test/test_StringIO.py index e74a427af0b3..c61f7cc54a3c 100644 --- a/Lib/test/test_StringIO.py +++ b/Lib/test/test_StringIO.py @@ -44,6 +44,13 @@ class TestGenericStringIO(unittest.TestCase): f.seek(0) self.assertEqual(f.getvalue(), 'abc') + def test_writelines_error(self): + def errorGen(): + yield 'a' + raise KeyboardInterrupt() + f = self.MODULE.StringIO() + self.assertRaises(KeyboardInterrupt, f.writelines, errorGen()) + def test_truncate(self): eq = self.assertEqual f = self.MODULE.StringIO() diff --git a/Misc/ACKS b/Misc/ACKS index 3c59b4f138f1..c599172bdf57 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -49,6 +49,7 @@ Reimer Behrends Thomas Bellman Juan M. Bello Rivas Alexander Belopolsky +Andrew Bennetts Andy Bensky Michel Van den Bergh Eric Beser diff --git a/Misc/NEWS b/Misc/NEWS index cc2ac30af516..4d87425b8358 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -16,6 +16,9 @@ Core and builtins Extension Modules ----------------- +- Patches #1298449 and #1298499: Add some missing checks for error + returns in cStringIO.c. + - Patch #1297028: fix segfault if call type on MultibyteCodec, MultibyteStreamReader, or MultibyteStreamWriter. diff --git a/Modules/cStringIO.c b/Modules/cStringIO.c index b7333fdd380d..e89111415cf4 100644 --- a/Modules/cStringIO.c +++ b/Modules/cStringIO.c @@ -241,7 +241,10 @@ IO_readlines(IOobject *self, PyObject *args) { line = PyString_FromStringAndSize (output, n); if (!line) goto err; - PyList_Append (result, line); + if (PyList_Append (result, line) == -1) { + Py_DECREF (line); + goto err; + } Py_DECREF (line); length += n; if (hint > 0 && length >= hint) @@ -440,11 +443,17 @@ O_writelines(Oobject *self, PyObject *args) { Py_DECREF(it); Py_DECREF(s); return NULL; - } - Py_DECREF(s); - } - Py_DECREF(it); - Py_RETURN_NONE; + } + Py_DECREF(s); + } + + Py_DECREF(it); + + /* See if PyIter_Next failed */ + if (PyErr_Occurred()) + return NULL; + + Py_RETURN_NONE; } static struct PyMethodDef O_methods[] = {