Skip to content

Commit

Permalink
[3.12] gh-105375: Improve error handling in _elementtree (GH-105591) (#…
Browse files Browse the repository at this point in the history
…105600)

Fix bugs where exceptions could end up being overwritten.
(cherry picked from commit 00b599a)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
  • Loading branch information
miss-islington and erlend-aasland committed Jun 9, 2023
1 parent e0087df commit 411366c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
@@ -0,0 +1 @@
Fix bugs in :mod:`!_elementtree` where exceptions could be overwritten.
10 changes: 7 additions & 3 deletions Modules/_elementtree.c
Expand Up @@ -3261,10 +3261,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;
Expand Down

0 comments on commit 411366c

Please sign in to comment.