From: Rob Richards Date: Mon, 18 Apr 2005 23:08:41 +0000 (+0000) Subject: MFH: Fix bug #32755 Segfault in replaceChild() when DocumentFragment has no children X-Git-Tag: php-5.0.5RC1~418 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9f0a5dc5e08f57e251a257782886c06f5143a8a0;p=php MFH: Fix bug #32755 Segfault in replaceChild() when DocumentFragment has no children update test --- diff --git a/ext/dom/node.c b/ext/dom/node.c index 8a581baa19..cba2f80b54 100644 --- a/ext/dom/node.c +++ b/ext/dom/node.c @@ -1134,7 +1134,9 @@ PHP_FUNCTION(dom_node_replace_child) xmlUnlinkNode(oldchild); newchild = _php_dom_insert_fragment(nodep, prevsib, nextsib, newchild, intern, newchildobj TSRMLS_CC); - dom_reconcile_ns(nodep->doc, newchild); + if (newchild) { + dom_reconcile_ns(nodep->doc, newchild); + } } else if (oldchild != newchild) { if (newchild->doc == NULL && nodep->doc != NULL) { xmlSetTreeDoc(newchild, nodep->doc); diff --git a/ext/dom/tests/bug32615.phpt b/ext/dom/tests/bug32615.phpt index 84891f3bb4..e48973429a 100644 --- a/ext/dom/tests/bug32615.phpt +++ b/ext/dom/tests/bug32615.phpt @@ -62,6 +62,12 @@ $frag->appendChild(new DOMElement('second')); $frag->appendChild(new DOMElement('third')); $root->insertBefore($frag, $node); +echo $dom->saveXML()."\n"; + +$frag = $dom->createDocumentFragment(); +$root = $dom->documentElement; +$root->replaceChild($frag, $root->firstChild); + echo $dom->saveXML(); ?> @@ -73,3 +79,6 @@ echo $dom->saveXML(); + + +