-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-31499, xml.etree: Fix xmlparser_gc_clear() crash #3641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
xml.etree: xmlparser_gc_clear() now sets self.parser to NULL to prevent a crash in xmlparser_dealloc() if xmlparser_gc_clear() was called previously by the garbage collector, because the parser was part of a reference cycle.
Co-Authored-By: Serhiy Storchaka <[email protected]>
Modules/_elementtree.c
Outdated
@@ -3411,7 +3411,10 @@ xmlparser_gc_traverse(XMLParserObject *self, visitproc visit, void *arg) | |||
static int | |||
xmlparser_gc_clear(XMLParserObject *self) | |||
{ | |||
EXPAT(ParserFree)(self->parser); | |||
if (self->parser != NULL) { | |||
EXPAT(ParserFree)(self->parser); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it would be safer to set self->parser = NULL
before calling ParserFree
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO it's overkill. EXPAT(ParserFree) calls a C function which is outside the "Python" world, I don't see how it could trigger a reentrant call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I made the change anyway. It doesn't harm much :-)
@@ -0,0 +1,3 @@ | |||
xml.etree: xmlparser_gc_clear() now sets self.parser to NULL to prevent a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too much implementation details. They are good on the tracker or in commit message, but not in a changelog. Look at this from the point of view of common Python user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, I simplified the NEWS entry.
Thanks for your review @serhiy-storchaka! |
Thanks @Haypo for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6. |
…3641) * bpo-31499, xml.etree: Fix xmlparser_gc_clear() crash xml.etree: xmlparser_gc_clear() now sets self.parser to NULL to prevent a crash in xmlparser_dealloc() if xmlparser_gc_clear() was called previously by the garbage collector, because the parser was part of a reference cycle. Co-Authored-By: Serhiy Storchaka <[email protected]> (cherry picked from commit e727d41)
GH-3645 is a backport of this pull request to the 3.6 branch. |
…3645) * bpo-31499, xml.etree: Fix xmlparser_gc_clear() crash xml.etree: xmlparser_gc_clear() now sets self.parser to NULL to prevent a crash in xmlparser_dealloc() if xmlparser_gc_clear() was called previously by the garbage collector, because the parser was part of a reference cycle. Co-Authored-By: Serhiy Storchaka <[email protected]> (cherry picked from commit e727d41)
xml.etree: xmlparser_gc_clear() now sets self.parser to NULL to prevent a
crash in xmlparser_dealloc() if xmlparser_gc_clear() was called previously
by the garbage collector, because the parser was part of a reference cycle.
https://bugs.python.org/issue31499