summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-06-09 21:15:24 (GMT)
committerGitHub <noreply@github.com>2023-06-09 21:15:24 (GMT)
commit411366ccdb7708cbf4e00db9186c2cffb3a0c652 (patch)
tree542f066c860323bb590e5b61ec84e6fb8c27da82 /Modules
parente0087df65df485478401aec321b22e2f92407cd3 (diff)
downloadcpython-411366ccdb7708cbf4e00db9186c2cffb3a0c652.zip
cpython-411366ccdb7708cbf4e00db9186c2cffb3a0c652.tar.gz
cpython-411366ccdb7708cbf4e00db9186c2cffb3a0c652.tar.bz2
[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 00b599ab5a76023fa0083d7cc5d3c569342a5191) Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_elementtree.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index 00d9f64..6244fcc 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -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;