summaryrefslogtreecommitdiff
path: root/ext/simplexml
diff options
context:
space:
mode:
authorAntony Dovgal <tony2001@php.net>2006-11-28 18:59:53 +0000
committerAntony Dovgal <tony2001@php.net>2006-11-28 18:59:53 +0000
commitd55eb93c945e462a215df63b6dc13cdb441ba208 (patch)
tree92880bd514ee7f6489244ca2390fe42467bd2396 /ext/simplexml
parentbb30875db6025aedec2a33f88374bc4a49ab8c60 (diff)
downloadphp-git-d55eb93c945e462a215df63b6dc13cdb441ba208.tar.gz
MFH: fix #39662 (Segfault when calling asXML() of a cloned SimpleXMLElement)
Diffstat (limited to 'ext/simplexml')
-rw-r--r--ext/simplexml/simplexml.c1
-rw-r--r--ext/simplexml/tests/bug39662.phpt39
2 files changed, 40 insertions, 0 deletions
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c
index 3a00fc909a..43c6065fb5 100644
--- a/ext/simplexml/simplexml.c
+++ b/ext/simplexml/simplexml.c
@@ -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
index 0000000000..47a0c27068
--- /dev/null
+++ b/ext/simplexml/tests/bug39662.phpt
@@ -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