]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Protection against picling to/from closed (real) file.
authorGuido van Rossum <guido@python.org>
Mon, 29 Mar 1999 20:00:14 +0000 (20:00 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 29 Mar 1999 20:00:14 +0000 (20:00 +0000)
The problem was reported by Moshe Zadka.

Modules/cPickle.c

index 3bf9ba112604605f378c8a86c577d9ff68e3964e..614ff06c25952d1fffbaafde9f5a017411a397c5 100644 (file)
@@ -2072,6 +2072,10 @@ newPicklerobject(PyObject *file, int bin) {
 
     if (PyFile_Check(file)) {
         self->fp = PyFile_AsFile(file);
+       if (self->fp == NULL) {
+           PyErr_SetString(PyExc_IOError, "output file closed");
+           return NULL;
+       }
         self->write_func = write_file;
     }
     else if (PycStringIO_OutputCheck(file)) {
@@ -3897,6 +3901,10 @@ newUnpicklerobject(PyObject *f) {
     /* Set read, readline based on type of f */
     if (PyFile_Check(f)) {
         self->fp = PyFile_AsFile(f);
+       if (self->fp == NULL) {
+           PyErr_SetString(PyExc_IOError, "input file closed");
+           return NULL;
+       }
         self->read_func = read_file;
         self->readline_func = readline_file;
     }