[3.11] gh-105375: Improve errnomodule error handling (#105590) (#105595)

(cherry picked from commit eede1d2f48)

Bail immediately if an exception is set, to prevent exceptions from
being overwritten.
This commit is contained in:
Erlend E. Aasland 2023-06-09 22:35:30 +02:00 committed by GitHub
parent 4d4251d6ec
commit 76682ba7af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View file

@ -0,0 +1 @@
Fix bugs in :mod:`pickle` where exceptions could be overwritten.

View file

@ -79,9 +79,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) {
if (error_dict == NULL) {
return -1;
}
if (PyDict_SetItemString(module_dict, "errorcode", error_dict) < 0) {