Skip to content

Commit 00b599a

Browse files
gh-105375: Improve error handling in _elementtree (#105591)
Fix bugs where exceptions could end up being overwritten.
1 parent f668f73 commit 00b599a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed
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

+7-3
Original file line numberDiff line numberDiff line change
@@ -3259,10 +3259,14 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in,
32593259
}
32603260
while (attrib_in[0] && attrib_in[1]) {
32613261
PyObject* key = makeuniversal(self, attrib_in[0]);
3262+
if (key == NULL) {
3263+
Py_DECREF(attrib);
3264+
Py_DECREF(tag);
3265+
return;
3266+
}
32623267
PyObject* value = PyUnicode_DecodeUTF8(attrib_in[1], strlen(attrib_in[1]), "strict");
3263-
if (!key || !value) {
3264-
Py_XDECREF(value);
3265-
Py_XDECREF(key);
3268+
if (value == NULL) {
3269+
Py_DECREF(key);
32663270
Py_DECREF(attrib);
32673271
Py_DECREF(tag);
32683272
return;

0 commit comments

Comments
 (0)