]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-105375: Improve error handling in _elementtree (GH-105591) (#105601)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 9 Jun 2023 21:19:59 +0000 (14:19 -0700)
committerGitHub <noreply@github.com>
Fri, 9 Jun 2023 21:19:59 +0000 (21:19 +0000)
Fix bugs where exceptions could end up being overwritten.
(cherry picked from commit 00b599ab5a76023fa0083d7cc5d3c569342a5191)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Misc/NEWS.d/next/Library/2023-06-09-21-25-14.gh-issue-105375.95g1eI.rst [new file with mode: 0644]
Modules/_elementtree.c

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 (file)
index 0000000..1894b2b
--- /dev/null
@@ -0,0 +1 @@
+Fix bugs in :mod:`!_elementtree` where exceptions could be overwritten.
index 89f877f6e1279fbbe69877882d1ab2ba8fd4d9f2..12d22337d8217a3a4a6c7278b6b2c734bdcaeb27 100644 (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;