summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-06-09 23:22:10 (GMT)
committerGitHub <noreply@github.com>2023-06-09 23:22:10 (GMT)
commit8c4cf96a06e2483a11a4cb34c550df5bd22f990b (patch)
tree8d9cca204b25e1f0fa4c1ab610ac34d989dc3561
parent4fbbf699c0d72f6db62484c88a05c826c3703eb5 (diff)
downloadcpython-8c4cf96a06e2483a11a4cb34c550df5bd22f990b.zip
cpython-8c4cf96a06e2483a11a4cb34c550df5bd22f990b.tar.gz
cpython-8c4cf96a06e2483a11a4cb34c550df5bd22f990b.tar.bz2
[3.12] gh-105375: Improve error handling in `zoneinfo` module (GH-105586) (#105612)
Fix bugs where exceptions could end up being overwritten because of deferred error handling. (cherry picked from commit 33c92c4f15539806c8aff8574ff30a8b307e3e4d) Co-authored-by: Nikita Sobolev <mail@sobolevn.me> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
-rw-r--r--Misc/NEWS.d/next/Library/2023-06-09-21-11-28.gh-issue-105375.4Mxn7t.rst1
-rw-r--r--Modules/_zoneinfo.c17
2 files changed, 12 insertions, 6 deletions
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
index 0000000..4202b75
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-06-09-21-11-28.gh-issue-105375.4Mxn7t.rst
@@ -0,0 +1 @@
+Fix bugs in :mod:`zoneinfo` where exceptions could be overwritten.
diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c
index c8c791b..38b806c 100644
--- a/Modules/_zoneinfo.c
+++ b/Modules/_zoneinfo.c
@@ -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;
}