From: Guido van Rossum Date: Mon, 29 Mar 1999 20:00:14 +0000 (+0000) Subject: Protection against picling to/from closed (real) file. X-Git-Tag: v1.5.2c1~56 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c91fcaa43b5348ffad993b7e7da251f41abb46d2;p=thirdparty%2FPython%2Fcpython.git Protection against picling to/from closed (real) file. The problem was reported by Moshe Zadka. --- diff --git a/Modules/cPickle.c b/Modules/cPickle.c index 3bf9ba112604..614ff06c2595 100644 --- a/Modules/cPickle.c +++ b/Modules/cPickle.c @@ -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; }