Skip to content

Commit e474862

Browse files
[3.11] gh-105375: Improve error handling in _elementtree (GH-105591) (#105601)
Fix bugs where exceptions could end up being overwritten. (cherry picked from commit 00b599a) Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent c1797f6 commit e474862

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bugs in :mod:`!_elementtree` where exceptions could be overwritten.

Modules/_elementtree.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3263,10 +3263,14 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in,
32633263
}
32643264
while (attrib_in[0] && attrib_in[1]) {
32653265
PyObject* key = makeuniversal(self, attrib_in[0]);
3266+
if (key == NULL) {
3267+
Py_DECREF(attrib);
3268+
Py_DECREF(tag);
3269+
return;
3270+
}
32663271
PyObject* value = PyUnicode_DecodeUTF8(attrib_in[1], strlen(attrib_in[1]), "strict");
3267-
if (!key || !value) {
3268-
Py_XDECREF(value);
3269-
Py_XDECREF(key);
3272+
if (value == NULL) {
3273+
Py_DECREF(key);
32703274
Py_DECREF(attrib);
32713275
Py_DECREF(tag);
32723276
return;

0 commit comments

Comments
 (0)