]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-105375: Improve errnomodule error handling (#105590) (#105596)
authorErlend E. Aasland <erlend.aasland@protonmail.com>
Fri, 9 Jun 2023 20:36:53 +0000 (22:36 +0200)
committerGitHub <noreply@github.com>
Fri, 9 Jun 2023 20:36:53 +0000 (20:36 +0000)
(cherry picked from commit eede1d2f48b4fe7f7918952d9ebeb744b58668c1)

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 fddde960a5fe9a3bef14c46ca4ca3250d4caccb4..301ad8313bc51278263457dca6610de3e9a847ac 100644 (file)
@@ -81,9 +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) {
+    if (error_dict == NULL) {
         return -1;
     }
     if (PyDict_SetItemString(module_dict, "errorcode", error_dict) < 0) {