mirror of
https://github.com/python/cpython.git
synced 2025-11-13 15:40:05 +00:00
Do more robust test of whether global objects are accessible.
PyImport_ImportModule() is not guaranteed to return a module object. When another type of object was returned, the PyModule_GetDict() call return NULL and the subsequent GetItem() seg faulted. Bug fix candidate.
This commit is contained in:
parent
f2a0473350
commit
0e1f7a82e9
1 changed files with 3 additions and 4 deletions
|
|
@ -1719,10 +1719,7 @@ save_global(Picklerobject *self, PyObject *args, PyObject *name)
|
||||||
"OSS", args, module, global_name);
|
"OSS", args, module, global_name);
|
||||||
goto finally;
|
goto finally;
|
||||||
}
|
}
|
||||||
/* borrowed ref */
|
klass = PyObject_GetAttrString(mod, name_str);
|
||||||
moddict = PyModule_GetDict(mod);
|
|
||||||
/* borrowed ref */
|
|
||||||
klass = PyDict_GetItemString(moddict, name_str);
|
|
||||||
if (klass == NULL) {
|
if (klass == NULL) {
|
||||||
cPickle_ErrFormat(PicklingError,
|
cPickle_ErrFormat(PicklingError,
|
||||||
"Can't pickle %s: it's not found as %s.%s",
|
"Can't pickle %s: it's not found as %s.%s",
|
||||||
|
|
@ -1730,11 +1727,13 @@ save_global(Picklerobject *self, PyObject *args, PyObject *name)
|
||||||
goto finally;
|
goto finally;
|
||||||
}
|
}
|
||||||
if (klass != args) {
|
if (klass != args) {
|
||||||
|
Py_DECREF(klass);
|
||||||
cPickle_ErrFormat(PicklingError,
|
cPickle_ErrFormat(PicklingError,
|
||||||
"Can't pickle %s: it's not the same object as %s.%s",
|
"Can't pickle %s: it's not the same object as %s.%s",
|
||||||
"OSS", args, module, global_name);
|
"OSS", args, module, global_name);
|
||||||
goto finally;
|
goto finally;
|
||||||
}
|
}
|
||||||
|
Py_DECREF(klass);
|
||||||
|
|
||||||
if ((*self->write_func)(self, &global, 1) < 0)
|
if ((*self->write_func)(self, &global, 1) < 0)
|
||||||
goto finally;
|
goto finally;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue