summaryrefslogtreecommitdiff
path: root/ext/simplexml
diff options
context:
space:
mode:
authorRob Richards <rrichards@php.net>2007-07-31 15:40:49 +0000
committerRob Richards <rrichards@php.net>2007-07-31 15:40:49 +0000
commite0a2d149f5304b39c6499ddb5d4547284bd68138 (patch)
treeeb8be52ccc10e951d0959f9ac93e94c0ce8f035a /ext/simplexml
parentce582024a51050c3f39748a7eaf44d41ab2f5cdc (diff)
downloadphp-git-e0a2d149f5304b39c6499ddb5d4547284bd68138.tar.gz
MFH: fix bug #41833 (addChild() on a non-existent node, no node created, getName() segfaults)
Diffstat (limited to 'ext/simplexml')
-rw-r--r--ext/simplexml/simplexml.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c
index 47260f965f..c97bfafc72 100644
--- a/ext/simplexml/simplexml.c
+++ b/ext/simplexml/simplexml.c
@@ -1563,6 +1563,11 @@ SXE_METHOD(addChild)
node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
+ if (node == NULL) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot add child. Parent is not a permanent member of the XML tree");
+ return;
+ }
+
localname = xmlSplitQName2((xmlChar *)qname, &prefix);
if (localname == NULL) {
localname = xmlStrdup((xmlChar *)qname);
@@ -1575,9 +1580,7 @@ SXE_METHOD(addChild)
newnode->ns = NULL;
nsptr = xmlNewNs(newnode, (xmlChar *)nsuri, prefix);
} else {
- if (node) {
- nsptr = xmlSearchNsByHref(node->doc, node, (xmlChar *)nsuri);
- }
+ nsptr = xmlSearchNsByHref(node->doc, node, (xmlChar *)nsuri);
if (nsptr == NULL) {
nsptr = xmlNewNs(newnode, (xmlChar *)nsuri, prefix);
}