fix: addSibling double-free when text merging via last sibling#263
Draft
toddr-bot wants to merge 1 commit into
Draft
fix: addSibling double-free when text merging via last sibling#263toddr-bot wants to merge 1 commit into
toddr-bot wants to merge 1 commit into
Conversation
xmlAddSibling navigates to parent->last before checking for text merges. The old code only checked self->type, so when self was not a text node but parent->last was, libxml2 merged and freed nNode without the proxy being disconnected — use-after-free / double-free. Replace the two-branch predict-and-copy approach with the same ret != nNode detection pattern used by addChild: save the proxy before calling xmlAddSibling, then NULL it out if the node was consumed by a merge. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
addSiblinghad incomplete text-merge detection: it only checked whetherselfwas a text node, butxmlAddSiblingactually navigates toself->parent->lastbefore merging. Whenselfwas not text but the last sibling was, libxml2 merged and freednNodewithout the proxy being disconnected — causing a use-after-free / double-free.Replaced the two-branch predict-and-copy approach with the same
ret != nNodedetection pattern used byaddChild: save the proxy before callingxmlAddSibling, then NULL it out if the node was consumed by a merge. This handles all merge cases regardless of which sibling triggers the merge.Fixes #246
Changes
addSiblingmerge handling to followaddChild's proven patternaddSiblingcalls with text nodes on a non-text element)Test plan
t/04node.treproduces the double-free scenario from the issueGenerated by Kōan /fix
Quality Report
Changes: 2 files changed, 41 insertions(+), 27 deletions(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline