[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 00b599ab5a)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
This commit is contained in:
Miss Islington (bot) 2023-06-09 14:19:59 -07:00 committed by GitHub
parent c1797f661d
commit e4748628e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View file

@ -0,0 +1 @@
Fix bugs in :mod:`!_elementtree` where exceptions could be overwritten.

View file

@ -3263,10 +3263,14 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in,
}
while (attrib_in[0] && attrib_in[1]) {
PyObject* key = makeuniversal(self, attrib_in[0]);
if (key == NULL) {
Py_DECREF(attrib);
Py_DECREF(tag);
return;
}
PyObject* value = PyUnicode_DecodeUTF8(attrib_in[1], strlen(attrib_in[1]), "strict");
if (!key || !value) {
Py_XDECREF(value);
Py_XDECREF(key);
if (value == NULL) {
Py_DECREF(key);
Py_DECREF(attrib);
Py_DECREF(tag);
return;