Skip to content

Commit 76682ba

Browse files
[3.11] gh-105375: Improve errnomodule error handling (#105590) (#105595)
(cherry picked from commit eede1d2) Bail immediately if an exception is set, to prevent exceptions from being overwritten.
1 parent 4d4251d commit 76682ba

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
@@ -79,9 +79,12 @@ _add_errcode(PyObject *module_dict, PyObject *error_dict, const char *name_str,
7979
static int
8080
errno_exec(PyObject *module)
8181
{
82-
PyObject *module_dict = PyModule_GetDict(module);
82+
PyObject *module_dict = PyModule_GetDict(module); // Borrowed ref.
83+
if (module_dict == NULL) {
84+
return -1;
85+
}
8386
PyObject *error_dict = PyDict_New();
84-
if (!module_dict || !error_dict) {
87+
if (error_dict == NULL) {
8588
return -1;
8689
}
8790
if (PyDict_SetItemString(module_dict, "errorcode", error_dict) < 0) {

0 commit comments

Comments
 (0)