Skip to content

Commit

Permalink
pythongh-105375: Improve errnomodule error handling (python#105590)
Browse files Browse the repository at this point in the history
Bail immediately if an exception is set, to prevent exceptions from
being overwritten.
  • Loading branch information
erlend-aasland committed Jun 9, 2023
1 parent 89aac6f commit eede1d2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bugs in :mod:`pickle` where exceptions could be overwritten.
8 changes: 5 additions & 3 deletions Modules/errnomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@ _add_errcode(PyObject *module_dict, PyObject *error_dict, const char *name_str,
static int
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();
if (!module_dict || !error_dict) {
Py_XDECREF(error_dict);
if (error_dict == NULL) {
return -1;
}
if (PyDict_SetItemString(module_dict, "errorcode", error_dict) < 0) {
Expand Down

0 comments on commit eede1d2

Please sign in to comment.