Skip to content

Commit 411366c

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

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
@@ -3261,10 +3261,14 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in,
32613261
}
32623262
while (attrib_in[0] && attrib_in[1]) {
32633263
PyObject* key = makeuniversal(self, attrib_in[0]);
3264+
if (key == NULL) {
3265+
Py_DECREF(attrib);
3266+
Py_DECREF(tag);
3267+
return;
3268+
}
32643269
PyObject* value = PyUnicode_DecodeUTF8(attrib_in[1], strlen(attrib_in[1]), "strict");
3265-
if (!key || !value) {
3266-
Py_XDECREF(value);
3267-
Py_XDECREF(key);
3270+
if (value == NULL) {
3271+
Py_DECREF(key);
32683272
Py_DECREF(attrib);
32693273
Py_DECREF(tag);
32703274
return;

0 commit comments

Comments
 (0)