diff options
author | tjb900 <ozburgess@gmail.com> | 2019-02-18 15:30:51 (GMT) |
---|---|---|
committer | Antoine Pitrou <pitrou@free.fr> | 2019-02-18 15:30:51 (GMT) |
commit | 4371c0a9c0848f7a0947d43f26f234842b41efdf (patch) | |
tree | 122d9ea80e833f00f856fa58625b7a17f3573ad3 /Modules/_pickle.c | |
parent | 4a7f44a2ed49ff1e87db062e7177a56c6e4bbdb0 (diff) | |
download | cpython-4371c0a9c0848f7a0947d43f26f234842b41efdf.zip cpython-4371c0a9c0848f7a0947d43f26f234842b41efdf.tar.gz cpython-4371c0a9c0848f7a0947d43f26f234842b41efdf.tar.bz2 |
bpo-34572: change _pickle unpickling to use import rather than retrieving from sys.modules (GH-9047)
Fix C implementation of pickle.loads to use importlib's locking mechanisms, and thereby avoid using partially-loaded modules.
Diffstat (limited to 'Modules/_pickle.c')
-rw-r--r-- | Modules/_pickle.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/Modules/_pickle.c b/Modules/_pickle.c index 58cd09c..2b97294 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -6636,13 +6636,13 @@ _pickle_Unpickler_find_class_impl(UnpicklerObject *self, } } - module = PyImport_GetModule(module_name); + /* + * we don't use PyImport_GetModule here, because it can return partially- + * initialised modules, which then cause the getattribute to fail. + */ + module = PyImport_Import(module_name); if (module == NULL) { - if (PyErr_Occurred()) - return NULL; - module = PyImport_Import(module_name); - if (module == NULL) - return NULL; + return NULL; } global = getattribute(module, global_name, self->proto >= 4); Py_DECREF(module); |