]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-105375: Improve errnomodule error handling (#105590)
authorErlend E. Aasland <erlend.aasland@protonmail.com>
Fri, 9 Jun 2023 19:57:25 +0000 (21:57 +0200)
committerGitHub <noreply@github.com>
Fri, 9 Jun 2023 19:57:25 +0000 (21:57 +0200)
Bail immediately if an exception is set, to prevent exceptions from
being overwritten.

Misc/NEWS.d/next/Library/2023-06-09-21-04-39.gh-issue-105375.bTcqS9.rst [new file with mode: 0644]
Modules/errnomodule.c

diff --git a/Misc/NEWS.d/next/Library/2023-06-09-21-04-39.gh-issue-105375.bTcqS9.rst b/Misc/NEWS.d/next/Library/2023-06-09-21-04-39.gh-issue-105375.bTcqS9.rst
new file mode 100644 (file)
index 0000000..3030477
--- /dev/null
@@ -0,0 +1 @@
+Fix bugs in :mod:`pickle` where exceptions could be overwritten.
index 3d0c2d7ae945bceccee553e203c498d1be5bc374..301ad8313bc51278263457dca6610de3e9a847ac 100644 (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) {