gh-105375: Improve errnomodule error handling (#105590)

Bail immediately if an exception is set, to prevent exceptions from
being overwritten.
This commit is contained in:
Erlend E. Aasland 2023-06-09 21:57:25 +02:00 committed by GitHub
parent 89aac6f6b7
commit eede1d2f48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

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

View File

@ -81,10 +81,12 @@ end:
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) {