Skip to content

Commit 8c4cf96

Browse files
miss-islingtonsobolevnerlend-aasland
authored
[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 33c92c4) Co-authored-by: Nikita Sobolev <[email protected]> Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent 4fbbf69 commit 8c4cf96

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bugs in :mod:`zoneinfo` where exceptions could be overwritten.

Modules/_zoneinfo.c

+11-6
Original file line numberDiff line numberDiff line change
@@ -694,14 +694,19 @@ zoneinfo_fromutc(PyObject *obj_self, PyObject *dt)
694694
}
695695
else {
696696
PyObject *replace = PyObject_GetAttrString(tmp, "replace");
697+
Py_DECREF(tmp);
698+
if (replace == NULL) {
699+
return NULL;
700+
}
697701
PyObject *args = PyTuple_New(0);
702+
if (args == NULL) {
703+
Py_DECREF(replace);
704+
return NULL;
705+
}
698706
PyObject *kwargs = PyDict_New();
699-
700-
Py_DECREF(tmp);
701-
if (args == NULL || kwargs == NULL || replace == NULL) {
702-
Py_XDECREF(args);
703-
Py_XDECREF(kwargs);
704-
Py_XDECREF(replace);
707+
if (kwargs == NULL) {
708+
Py_DECREF(replace);
709+
Py_DECREF(args);
705710
return NULL;
706711
}
707712

0 commit comments

Comments
 (0)