summaryrefslogtreecommitdiffstats
path: root/Modules/cPickle.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1999-03-29 20:00:14 (GMT)
committerGuido van Rossum <guido@python.org>1999-03-29 20:00:14 (GMT)
commitc91fcaa43b5348ffad993b7e7da251f41abb46d2 (patch)
treef2173b8a6e37f7e10a3484d98ddd20f36edcf2b9 /Modules/cPickle.c
parent89ae2b9f071cb78322fd1df1571027cd7159a698 (diff)
downloadcpython-c91fcaa43b5348ffad993b7e7da251f41abb46d2.zip
cpython-c91fcaa43b5348ffad993b7e7da251f41abb46d2.tar.gz
cpython-c91fcaa43b5348ffad993b7e7da251f41abb46d2.tar.bz2
Protection against picling to/from closed (real) file.
The problem was reported by Moshe Zadka.
Diffstat (limited to 'Modules/cPickle.c')
-rw-r--r--Modules/cPickle.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/Modules/cPickle.c b/Modules/cPickle.c
index 3bf9ba1..614ff06 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;
}