]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-105375: Improve error handling in `zoneinfo` module (#105586)
authorNikita Sobolev <mail@sobolevn.me>
Fri, 9 Jun 2023 21:48:54 +0000 (00:48 +0300)
committerGitHub <noreply@github.com>
Fri, 9 Jun 2023 21:48:54 +0000 (21:48 +0000)
Fix bugs where exceptions could end up being overwritten
because of deferred error handling.

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Misc/NEWS.d/next/Library/2023-06-09-21-11-28.gh-issue-105375.4Mxn7t.rst [new file with mode: 0644]
Modules/_zoneinfo.c

diff --git a/Misc/NEWS.d/next/Library/2023-06-09-21-11-28.gh-issue-105375.4Mxn7t.rst b/Misc/NEWS.d/next/Library/2023-06-09-21-11-28.gh-issue-105375.4Mxn7t.rst
new file mode 100644 (file)
index 0000000..4202b75
--- /dev/null
@@ -0,0 +1 @@
+Fix bugs in :mod:`zoneinfo` where exceptions could be overwritten.
index 0dcdb4da47d5dbd2dea8b828d24b405331b7cccc..0ced9d08b9eb75f929b57b4ca046ec4ba4bd57e5 100644 (file)
@@ -694,14 +694,19 @@ zoneinfo_fromutc(PyObject *obj_self, PyObject *dt)
         }
         else {
             PyObject *replace = PyObject_GetAttrString(tmp, "replace");
+            Py_DECREF(tmp);
+            if (replace == NULL) {
+                return NULL;
+            }
             PyObject *args = PyTuple_New(0);
+            if (args == NULL) {
+                Py_DECREF(replace);
+                return NULL;
+            }
             PyObject *kwargs = PyDict_New();
-
-            Py_DECREF(tmp);
-            if (args == NULL || kwargs == NULL || replace == NULL) {
-                Py_XDECREF(args);
-                Py_XDECREF(kwargs);
-                Py_XDECREF(replace);
+            if (kwargs == NULL) {
+                Py_DECREF(replace);
+                Py_DECREF(args);
                 return NULL;
             }