summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorscoder <stefan_ml@behnel.de>2017-09-14 20:00:03 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-09-14 20:00:03 (GMT)
commitc8d8e15bfc24abeeaaf3d8be9073276b0c011cdf (patch)
treefb00b03ee188ead7d74c74d8042b4c966cfeeaa3 /Modules
parent0b3a87ef54a0112b74e8a1d8c6f87d10db4239ab (diff)
downloadcpython-c8d8e15bfc24abeeaaf3d8be9073276b0c011cdf.zip
cpython-c8d8e15bfc24abeeaaf3d8be9073276b0c011cdf.tar.gz
cpython-c8d8e15bfc24abeeaaf3d8be9073276b0c011cdf.tar.bz2
bpo-31455: Fix an assertion failure in ElementTree.XMLParser(). (#3545)
* Avoid calling "PyObject_GetAttrString()" (and potentially executing user code) with a live exception set. * Ignore only AttributeError on attribute lookups in ElementTree.XMLParser() and propagate all other exceptions.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_elementtree.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index 98d5e7f..28d0181 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -3260,6 +3260,18 @@ xmlparser_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return (PyObject *)self;
}
+static int
+ignore_attribute_error(PyObject *value)
+{
+ if (value == NULL) {
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
+ return -1;
+ }
+ PyErr_Clear();
+ }
+ return 0;
+}
+
/*[clinic input]
_elementtree.XMLParser.__init__
@@ -3314,14 +3326,33 @@ _elementtree_XMLParser___init___impl(XMLParserObject *self, PyObject *html,
self->target = target;
self->handle_start = PyObject_GetAttrString(target, "start");
+ if (ignore_attribute_error(self->handle_start)) {
+ return -1;
+ }
self->handle_data = PyObject_GetAttrString(target, "data");
+ if (ignore_attribute_error(self->handle_data)) {
+ return -1;
+ }
self->handle_end = PyObject_GetAttrString(target, "end");
+ if (ignore_attribute_error(self->handle_end)) {
+ return -1;
+ }
self->handle_comment = PyObject_GetAttrString(target, "comment");
+ if (ignore_attribute_error(self->handle_comment)) {
+ return -1;
+ }
self->handle_pi = PyObject_GetAttrString(target, "pi");
+ if (ignore_attribute_error(self->handle_pi)) {
+ return -1;
+ }
self->handle_close = PyObject_GetAttrString(target, "close");
+ if (ignore_attribute_error(self->handle_close)) {
+ return -1;
+ }
self->handle_doctype = PyObject_GetAttrString(target, "doctype");
-
- PyErr_Clear();
+ if (ignore_attribute_error(self->handle_doctype)) {
+ return -1;
+ }
/* configure parser */
EXPAT(SetUserData)(self->parser, self);