]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Patch #1535500: fix segfault in BZ2File.writelines and make sure it
authorGeorg Brandl <georg@python.org>
Mon, 14 Aug 2006 21:42:58 +0000 (21:42 +0000)
committerGeorg Brandl <georg@python.org>
Mon, 14 Aug 2006 21:42:58 +0000 (21:42 +0000)
raises the correct exceptions.
 (backport from rev. 51285)

Lib/test/test_bz2.py
Misc/NEWS
Modules/bz2module.c

index 7bd8a1ccd227bb3a545a1a3e052b64b2b932a819..4e033942f9d435a7e31c636a6a1e0e15f988cd78 100644 (file)
@@ -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()
index 6b1a484e8b20d0e5d530556d9b9a7a3d4b11d271..37c31916aef1ee109a4a1d3dc42aa14e4e78672f 100644 (file)
--- 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.
 
index 91710686a0867f03287d2a406941c2a3507e4777..8d9eaf40a9c6fe171b27db2e7fa5330b363e8d9a 100644 (file)
@@ -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))