diff options
author | Erlend E. Aasland <erlend.aasland@protonmail.com> | 2023-06-09 20:35:03 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-09 20:35:03 (GMT) |
commit | 00b599ab5a76023fa0083d7cc5d3c569342a5191 (patch) | |
tree | a67345324f6bf18e43ba189c4985981cacd82e0f | |
parent | f668f73bc88cce0112b304d87aa998fb28013c71 (diff) | |
download | cpython-00b599ab5a76023fa0083d7cc5d3c569342a5191.zip cpython-00b599ab5a76023fa0083d7cc5d3c569342a5191.tar.gz cpython-00b599ab5a76023fa0083d7cc5d3c569342a5191.tar.bz2 |
gh-105375: Improve error handling in _elementtree (#105591)
Fix bugs where exceptions could end up being overwritten.
-rw-r--r-- | Misc/NEWS.d/next/Library/2023-06-09-21-25-14.gh-issue-105375.95g1eI.rst | 1 | ||||
-rw-r--r-- | Modules/_elementtree.c | 10 |
2 files changed, 8 insertions, 3 deletions
diff --git a/Misc/NEWS.d/next/Library/2023-06-09-21-25-14.gh-issue-105375.95g1eI.rst b/Misc/NEWS.d/next/Library/2023-06-09-21-25-14.gh-issue-105375.95g1eI.rst new file mode 100644 index 0000000..1894b2b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-06-09-21-25-14.gh-issue-105375.95g1eI.rst @@ -0,0 +1 @@ +Fix bugs in :mod:`!_elementtree` where exceptions could be overwritten. diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 1e9c8bc..21a6e4e 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -3259,10 +3259,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; |