Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0e1f7a8

Browse files
committed
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.
1 parent f2a0473 commit 0e1f7a8

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

Modules/cPickle.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,22 +1719,21 @@ save_global(Picklerobject *self, PyObject *args, PyObject *name)
17191719
"OSS", args, module, global_name);
17201720
goto finally;
17211721
}
1722-
/* borrowed ref */
1723-
moddict = PyModule_GetDict(mod);
1724-
/* borrowed ref */
1725-
klass = PyDict_GetItemString(moddict, name_str);
1722+
klass = PyObject_GetAttrString(mod, name_str);
17261723
if (klass == NULL) {
17271724
cPickle_ErrFormat(PicklingError,
17281725
"Can't pickle %s: it's not found as %s.%s",
17291726
"OSS", args, module, global_name);
17301727
goto finally;
17311728
}
17321729
if (klass != args) {
1730+
Py_DECREF(klass);
17331731
cPickle_ErrFormat(PicklingError,
17341732
"Can't pickle %s: it's not the same object as %s.%s",
17351733
"OSS", args, module, global_name);
17361734
goto finally;
17371735
}
1736+
Py_DECREF(klass);
17381737

17391738
if ((*self->write_func)(self, &global, 1) < 0)
17401739
goto finally;

0 commit comments

Comments
 (0)