Conversation
…comments ivy_appendchildxml() and ivy_appendchildxml2() unlinked and freed ws.xpathctx->node->children after serializing the result. The xpath context node is the document node, so when the document carries a comment or processing instruction before the root element, the unlink advanced doc->children to the root element and the subsequent xmlFreeNode() freed the root element while it was still linked in the document. cleanup_ws() then freed the same tree again via xmlFreeDoc(), aborting the backend with "double free detected". Without a prolog node the same two lines unlinked the root element and freed nothing, leaking the whole modified document tree on every call. ret is already a serialized copy of the document and cleanup_ws() frees ws.doc exactly once, so deleting the two lines fixes both the crash and the leak. Adds regression cases covering a prolog comment, a prolog processing instruction, and the 4-argument namespace variant.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: IvorySQL/IvorySQL/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
💤 Files with no reviewable changes (1)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe change removes redundant XML node cleanup from both ChangesAPPENDCHILDXML double-free fix
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Thanks for contributing to IvorySQL! |
Fixes #2134
Problem
APPENDCHILDXMLaborts the backend when the input document has a comment or processing instruction before the root element:Both the 3-argument form and the 4-argument namespace form (
ivy_appendchildxml/ivy_appendchildxml2) are affected.Root cause
After serializing the result, both functions ran:
ws.xpathctx->nodeis the document node, and with a prolog commentnode->childrenis that comment.xmlUnlinkNode()unlinks the comment and advancesdoc->childrento the root element, so the followingxmlFreeNode()frees the root element while it is still linked in the document.cleanup_ws()later callsxmlFreeDoc(ws.doc), which walks the child list starting at the already-freed root element — double free.Without a prolog node the same two lines unlinked the root element, freed nothing (
xmlFreeNode(NULL)), and leftxmlFreeDoc()with an empty document: the whole modified tree leaked on every call.Fix
Delete the two lines in both functions.
retis already a serialized copy andcleanup_ws()freesws.docexactly once, so nothing else is needed. This fixes both the crash and the per-call document leak.After the fix the statement above returns:
Verification
Debug build (
--enable-cassert --enable-debug --with-libxml --with-icu --with-uuid=e2fs), oracle compatible mode, server encoding UTF8, onmaster(63fb0bf):free(): double free detected in tcache 2(signal 6); the same happens for a prolog processing instruction and for the 4-argument namespace variant.make -C contrib/ivorysql_ora oracle-installcheck: 31/31 tests inORA_REGRESSbehave identically before and after the change (ora_xml_functionsgreen both times; the standalone-runora_sysviewenvironment diff is unchanged and unrelated).contrib/ivorysql_ora/sql/ora_xml_functions.sqlcover the prolog comment, the prolog processing instruction, and the namespace variant; expected output updated.Summary by CodeRabbit
Bug Fixes
Tests