Mercurial > cpython-lru_cache-weakref
changeset 39496:352ffe77b71d legacy-trunk
Patch #1535500: fix segfault in BZ2File.writelines and make sure it
raises the correct exceptions.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Mon, 14 Aug 2006 21:42:55 +0000 |
| parents | 14ec9cfd9760 |
| children | 9d64bd748320 |
| files | Lib/test/test_bz2.py Misc/NEWS Modules/bz2module.c |
| diffstat | 3 files changed, 22 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/Lib/test/test_bz2.py Mon Aug 14 21:34:08 2006 +0000 +++ b/Lib/test/test_bz2.py Mon Aug 14 21:42:55 2006 +0000 @@ -166,6 +166,8 @@ sio = StringIO(self.TEXT) bz2f.writelines(sio.readlines()) bz2f.close() + # patch #1535500 + self.assertRaises(ValueError, bz2f.writelines, ["a"]) f = open(self.filename, 'rb') self.assertEqual(self.decompress(f.read()), self.TEXT) f.close()
--- a/Misc/NEWS Mon Aug 14 21:34:08 2006 +0000 +++ b/Misc/NEWS Mon Aug 14 21:42:55 2006 +0000 @@ -79,6 +79,9 @@ Extension Modules ----------------- +- Patch #1535500: fix segfault in BZ2File.writelines and make sure it + raises the correct exceptions. + - Patch # 1536908: enable building ctypes on OpenBSD/AMD64. The '-no-stack-protector' compiler flag for OpenBSD has been removed.
--- a/Modules/bz2module.c Mon Aug 14 21:34:08 2006 +0000 +++ b/Modules/bz2module.c Mon Aug 14 21:42:55 2006 +0000 @@ -812,12 +812,12 @@ case MODE_CLOSED: PyErr_SetString(PyExc_ValueError, "I/O operation on closed file"); - goto cleanup;; + goto cleanup; default: PyErr_SetString(PyExc_IOError, "file is not ready for writing"); - goto cleanup;; + goto cleanup; } self->f_softspace = 0; @@ -861,6 +861,21 @@ int bzerror; ACQUIRE_LOCK(self); + switch (self->mode) { + case MODE_WRITE: + break; + + case MODE_CLOSED: + PyErr_SetString(PyExc_ValueError, + "I/O operation on closed file"); + goto error; + + default: + PyErr_SetString(PyExc_IOError, + "file is not ready for writing"); + goto error; + } + islist = PyList_Check(seq); if (!islist) { iter = PyObject_GetIter(seq);
