summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorOren Milman <orenmn@gmail.com>2017-10-20 20:42:35 (GMT)
committerBrett Cannon <brettcannon@users.noreply.github.com>2017-10-20 20:42:35 (GMT)
commitdb60a5bfa5d5f7a6f1538cc1fe76f0fda57b524e (patch)
treef5dafae436170814bce65b7e189d66ce8b3f2bf2 /Modules
parent56cb465cc93dcb35aaf7266ca3dbe2dcff1fac5f (diff)
downloadcpython-db60a5bfa5d5f7a6f1538cc1fe76f0fda57b524e.zip
cpython-db60a5bfa5d5f7a6f1538cc1fe76f0fda57b524e.tar.gz
cpython-db60a5bfa5d5f7a6f1538cc1fe76f0fda57b524e.tar.bz2
bpo-31781: Prevent crashes when calling methods of an uninitialized zipimport.zipimporter object (GH-3986)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/zipimport.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
index 895cd80..009480b 100644
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -322,6 +322,12 @@ get_module_info(ZipImporter *self, PyObject *fullname)
PyObject *path, *fullpath, *item;
struct st_zip_searchorder *zso;
+ if (self->prefix == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "zipimporter.__init__() wasn't called");
+ return MI_ERROR;
+ }
+
subname = get_subname(fullname);
if (subname == NULL)
return MI_ERROR;
@@ -652,6 +658,12 @@ zipimport_zipimporter_get_data_impl(ZipImporter *self, PyObject *path)
PyObject *toc_entry;
Py_ssize_t path_start, path_len, len;
+ if (self->archive == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "zipimporter.__init__() wasn't called");
+ return NULL;
+ }
+
#ifdef ALTSEP
path = _PyObject_CallMethodId((PyObject *)&PyUnicode_Type, &PyId_replace,
"OCC", path, ALTSEP, SEP);
@@ -1476,6 +1488,12 @@ get_module_code(ZipImporter *self, PyObject *fullname,
PyObject *path, *fullpath = NULL;
struct st_zip_searchorder *zso;
+ if (self->prefix == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "zipimporter.__init__() wasn't called");
+ return NULL;
+ }
+
subname = get_subname(fullname);
if (subname == NULL)
return NULL;