bpo-31455: avoid calling "PyObject_GetAttrString()" with a live exception set#3545
bpo-31455: avoid calling "PyObject_GetAttrString()" with a live exception set#3545serhiy-storchaka merged 5 commits intopython:masterfrom
Conversation
…ser code) with a live exception set.
|
Please open an issue on the bug tracker. This isn't a trivial change. I think that it would be better to silence only |
|
Found as part of #3279, which started showing side-effects due to this bug. |
…ser() and propagate all other exceptions.
|
PR updated, test and News entry added. |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
LGTM. I left just few nitpicks.
Lib/test/test_xml_etree.py
Outdated
|
|
||
| ET.XMLParser(target=RaisingBuilder(what=AttributeError)) | ||
| for event in ('start', 'data', 'end', 'comment', 'pi'): | ||
| ET.XMLParser(target=RaisingBuilder(event, what=AttributeError)) |
There was a problem hiding this comment.
Close the parser explicitly. Just for the case.
There was a problem hiding this comment.
Done. (Requires parsing something, though.)
Lib/test/test_xml_etree.py
Outdated
| self.assertEqual(child.tail, 'tail') | ||
| self.assertEqual(child.attrib, {}) | ||
|
|
||
| def test_exceptions(self): |
There was a problem hiding this comment.
Wouldn't XMLParserTest be better place? In any case I think it is better to place this method at the end of the class, after testing normal cases.
And maybe use more specific method name? "test_builder_attribute_errors" or something like.
There was a problem hiding this comment.
Done. I kept it in the test class because the exceptions are related to the behaviour of the TreeBuilder.
Modules/_elementtree.c
Outdated
| } | ||
|
|
||
| static int | ||
| ignore_attribute_error(PyObject *value) { |
There was a problem hiding this comment.
Put this { on new line.
Modules/_elementtree.c
Outdated
| self->target = target; | ||
|
|
||
| self->handle_start = PyObject_GetAttrString(target, "start"); | ||
| if (ignore_attribute_error(self->handle_start)) |
There was a problem hiding this comment.
New PEP 7 rules require braces even around simple if body.
There was a problem hiding this comment.
Done. (Sad in this case, given the relation between "active" code and error handling code.)
…isbehaviour, not basic behaviour.
|
PR updated. |
|
Thanks @scoder for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7, 3.6. |
|
Sorry, @scoder and @serhiy-storchaka, I could not cleanly backport this to |
…pythonGH-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. (cherry picked from commit c8d8e15)
|
GH-3585 is a backport of this pull request to the 3.6 branch. |
|
Thanks @scoder for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7. |
|
Sorry, @scoder and @serhiy-storchaka, I could not cleanly backport this to |
https://bugs.python.org/issue31455