Skip to content

Commit eede1d2

Browse files
gh-105375: Improve errnomodule error handling (#105590)
Bail immediately if an exception is set, to prevent exceptions from being overwritten.
1 parent 89aac6f commit eede1d2

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bugs in :mod:`pickle` where exceptions could be overwritten.

Modules/errnomodule.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,12 @@ _add_errcode(PyObject *module_dict, PyObject *error_dict, const char *name_str,
8181
static int
8282
errno_exec(PyObject *module)
8383
{
84-
PyObject *module_dict = PyModule_GetDict(module);
84+
PyObject *module_dict = PyModule_GetDict(module); // Borrowed ref.
85+
if (module_dict == NULL) {
86+
return -1;
87+
}
8588
PyObject *error_dict = PyDict_New();
86-
if (!module_dict || !error_dict) {
87-
Py_XDECREF(error_dict);
89+
if (error_dict == NULL) {
8890
return -1;
8991
}
9092
if (PyDict_SetItemString(module_dict, "errorcode", error_dict) < 0) {

0 commit comments

Comments
 (0)