Repository navigation
Fix NULL dereference in XMLNode::InsertAfterChild for adjacent re-insertion - #1103
Open
zhouyunding wants to merge 1 commit into
Open
zhouyunding wants to merge 1 commit into
zhouyunding wants to merge 1 commit into
Conversation
…ertion InsertAfterChild unlinked addThis before checking whether it was already the immediate next sibling of afterThis. Unlinking addThis cleared afterThis->_next, so the subsequent write to afterThis->_next->_prev dereferenced a null pointer. Return addThis early when it is already in place (issue leethomason#1101).
Author
|
Maintainers, when you have a chance, could you please review this fix? The PR description includes local Debug/Release CTest and xmltest results, but no remote checks are currently reported. Please let me know if any additional CI jobs or tests would be helpful. Thank you. |
This branch has not been deployed
This file contains hidden or 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
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.
Fixes #1101
Root cause
XMLNode::InsertAfterChild(a, b)crashes whenbis alreadya's immediate next sibling and is the last child, for example with<r><a/><b/></r>. The insertion preamble unlinksb(InsertChildPreamble→Unlink), which setsa->_nexttob->_next(i.e.0); the following code then writes throughafterThis->_next->_prev, dereferencing the just-cleared pointer — a null-pointer write (SEGV, exit 139).Fix
Return
addThiswithout unlinking it when it is already in the requested position (afterThis->_next == addThis). The guard follows the existing document, parent, and self-insertion checks, so it cannot bypass any of them; returningaddThismatches the header contract ("Returns the addThis argument or 0 if..."). Add regressions for adjacent last and middle nodes, covering the return pointer, first/last child, parent, bidirectional sibling links, and repeated insertion (idempotence, no duplicates or self-loops).Behavior change: re-inserting a node at its current position is now an idempotent no-op that returns
addThis, instead of crashing when the node is the last child (or needlessly unlinking/relinking otherwise). All existing move, self-insertion, and cross-document rejection semantics are unchanged.Validation on Windows with GCC 16.2.0, CMake/Ninja, static builds (reproduced again in independent fresh builds)
xmltestreportsPass 554, Fail 0in each configuration. The unmodified baseline reportsPass 528, Fail 0— the +26 new assertions all pass and the existing 528 assertions show no regression.git -c core.whitespace=cr-at-eol diff --checkpassed; the repository's existing CRLF line endings are preserved.