Skip to content

Commit e0087df

Browse files
[3.12] gh-105375: Improve errnomodule error handling (#105590) (#105596)
(cherry picked from commit eede1d2) Bail immediately if an exception is set, to prevent exceptions from being overwritten.
1 parent 04b76ec commit e0087df

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed
Lines changed: 1 addition & 0 deletions
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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +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) {
89+
if (error_dict == NULL) {
8790
return -1;
8891
}
8992
if (PyDict_SetItemString(module_dict, "errorcode", error_dict) < 0) {

0 commit comments

Comments
 (0)