summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2006-08-14 21:42:58 +0000
committerGeorg Brandl <georg@python.org>2006-08-14 21:42:58 +0000
commit28930e418b370237f3344bcdeee4b15fb4383f4d (patch)
tree9355f0d5a14e18103a02651dc4f6b84e32a58031
parent429036701c9e656af92c3b388b0b24cc1a0f08cd (diff)
downloadcpython-git-28930e418b370237f3344bcdeee4b15fb4383f4d.tar.gz
Patch #1535500: fix segfault in BZ2File.writelines and make sure it
raises the correct exceptions. (backport from rev. 51285)
-rw-r--r--Lib/test/test_bz2.py2
-rw-r--r--Misc/NEWS3
-rw-r--r--Modules/bz2module.c20
3 files changed, 22 insertions, 3 deletions
diff --git a/Lib/test/test_bz2.py b/Lib/test/test_bz2.py
index 7bd8a1ccd2..4e033942f9 100644
--- a/Lib/test/test_bz2.py
+++ b/Lib/test/test_bz2.py
@@ -166,6 +166,8 @@ class BZ2FileTest(BaseTest):
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()
diff --git a/Misc/NEWS b/Misc/NEWS
index 6b1a484e8b..37c31916ae 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -36,6 +36,9 @@ Core and builtins
Extension Modules
-----------------
+- Patch #1535500: fix segfault in BZ2File.writelines and make sure it
+ raises the correct exceptions.
+
- Bug #1471938: Fix curses module build problem on Solaris 8; patch by
Paul Eggert.
diff --git a/Modules/bz2module.c b/Modules/bz2module.c
index 91710686a0..8d9eaf40a9 100644
--- a/Modules/bz2module.c
+++ b/Modules/bz2module.c
@@ -812,12 +812,12 @@ BZ2File_write(BZ2FileObject *self, PyObject *args)
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 @@ BZ2File_writelines(BZ2FileObject *self, PyObject *seq)
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);
@@ -985,7 +1000,6 @@ BZ2File_seek(BZ2FileObject *self, PyObject *args)
size_t readsize;
int chunksize;
int bzerror;
- int rewind = 0;
PyObject *ret = NULL;
if (!PyArg_ParseTuple(args, "O|i:seek", &offobj, &where))