mirror of https://github.com/python/cpython
gh-105375: Improve errnomodule error handling (#105590)
Bail immediately if an exception is set, to prevent exceptions from being overwritten.
This commit is contained in:
parent
89aac6f6b7
commit
eede1d2f48
|
@ -0,0 +1 @@
|
||||||
|
Fix bugs in :mod:`pickle` where exceptions could be overwritten.
|
|
@ -81,10 +81,12 @@ end:
|
||||||
static int
|
static int
|
||||||
errno_exec(PyObject *module)
|
errno_exec(PyObject *module)
|
||||||
{
|
{
|
||||||
PyObject *module_dict = PyModule_GetDict(module);
|
PyObject *module_dict = PyModule_GetDict(module); // Borrowed ref.
|
||||||
|
if (module_dict == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
PyObject *error_dict = PyDict_New();
|
PyObject *error_dict = PyDict_New();
|
||||||
if (!module_dict || !error_dict) {
|
if (error_dict == NULL) {
|
||||||
Py_XDECREF(error_dict);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (PyDict_SetItemString(module_dict, "errorcode", error_dict) < 0) {
|
if (PyDict_SetItemString(module_dict, "errorcode", error_dict) < 0) {
|
||||||
|
|
Loading…
Reference in New Issue