-
Notifications
You must be signed in to change notification settings - Fork 254
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
Fix segfaults in destructor using xmlDeregisterNodeDefault
callback
#321
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This problem was surfaced by issue #268. We weren't doing a proper check for failed attribute creation in the attr method. This still fails and segaults, but the reason is now obvious.
HTML documents have lax parsing and can be created even without a root node. This results in errors when the document defers methods to the root node. This patch catches that circumstance and throws more descriptive errors to let you know what went wrong.
HTML document throws better errors when there is no root node
add assertion to catch failed attribute creation
update nan to 1.5.1 and fix issues with the latest v8
Added support for RELAX NG schema validation
Add .namespace() to Attribute
Upgrade to NAN 1.7.0
package.json: Add license attribute
Bindings for list of features from xmlHasFeature
Needed for node-gyp v2.0.0
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Libxml has a few functions that accept callbacks. One of those functions is xmlDeregisterNodeDefault. This function sets the default callback function that is called when any node is "deregistered" (i.e. before freeing). The callback is also called for all of the node's children.
We can use this function to prevent bad access related segmentation faults by setting a flag saying that the xmlNode has already been freed. The XmlNode destructor code will then check the flag and return if it has already been freed.
In
libxmljs.cc
:In
xml_node.h
:In
xml_node.cc
:Now every time an xmlNode (or any of its children) is freed, the callback will set a flag on the libxmljs Node object saying that the xmlNode has already been freed. Since the destructor will have this information it will not attempt to free the node or access properties of the node causing a segfault. This solution works without any additional ref counting code or memory leaks.