]> granicus.if.org Git - php/commitdiff
MFH: fix #39662 (Segfault when calling asXML() of a cloned SimpleXMLElement)
authorAntony Dovgal <tony2001@php.net>
Tue, 28 Nov 2006 18:59:53 +0000 (18:59 +0000)
committerAntony Dovgal <tony2001@php.net>
Tue, 28 Nov 2006 18:59:53 +0000 (18:59 +0000)
NEWS
ext/simplexml/simplexml.c
ext/simplexml/tests/bug39662.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 1816821d02781a919ca536225280a5c70a8e067a..77e201c5330c52770f4419b6bb5899cf4b142d93 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -43,6 +43,8 @@ PHP                                                                        NEWS
     php_filter.h).
 - Fixed wrong signature initialization in imagepng (Takeshi Abe)
 - Added optimization for imageline with horizontal and vertial lines (Pierre)
+- Fixed bug #39662 (Segfault when calling asXML() of a cloned SimpleXMLElement).
+  (Tony)
 - Fixed bug #39656 (crash when calling fetch() on a PDO statment object
   after closeCursor()). (Ilia, Tony)
 - Fixed bug #39653 (ext/dba doesn't check for db-4.5 and db-4.4 when db4 
index 3a00fc909aa1b14ba3a7cc416e478017dabe2437..43c6065fb547804bbc82d00a72d8be7f52e03d04 100644 (file)
@@ -1762,6 +1762,7 @@ sxe_object_clone(void *object, void **clone_ptr TSRMLS_DC)
        }
        if (sxe->node) {
                nodep = xmlDocCopyNode(sxe->node->node, docp, 1);
+               nodep->parent = sxe->node->node->parent;
        }
 
        php_libxml_increment_node_ptr((php_libxml_node_object *)clone, nodep, NULL TSRMLS_CC);
diff --git a/ext/simplexml/tests/bug39662.phpt b/ext/simplexml/tests/bug39662.phpt
new file mode 100644 (file)
index 0000000..47a0c27
--- /dev/null
@@ -0,0 +1,39 @@
+--TEST--
+Bug #39662 (Segfault when calling asXML() of a cloned SimpleXMLElement)
+--SKIPIF--
+<?php if (!extension_loaded("simplexml")) print "skip simplexml extension is not loaded"; ?>
+--FILE--
+<?php
+
+$xml = '<?xml version="1.0" encoding="utf-8" ?>
+<test>
+
+</test>';
+
+$root = simplexml_load_string($xml);
+$clone = clone $root;
+var_dump($root);
+var_dump($clone);
+var_dump($clone->asXML());
+
+echo "Done\n";
+?>
+--EXPECTF--    
+object(SimpleXMLElement)#%d (1) {
+  [0]=>
+  string(2) "
+
+"
+}
+object(SimpleXMLElement)#%d (1) {
+  [0]=>
+  string(2) "
+
+"
+}
+string(55) "<?xml version="1.0" encoding="utf-8"?>
+<test>
+
+</test>
+"
+Done