summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntony Dovgal <tony2001@php.net>2007-02-12 21:06:29 +0000
committerAntony Dovgal <tony2001@php.net>2007-02-12 21:06:29 +0000
commit2c31b1e194adc746597eb9ab2310e87e01bf86d4 (patch)
tree5207d91fc075b571374ddae384a546a7a6469343
parentcce7545d18ed7774b3938565dd1c770c9a14bbb9 (diff)
downloadphp-git-2c31b1e194adc746597eb9ab2310e87e01bf86d4.tar.gz
fix #40451 (addAttribute() may crash when used with non-existent child node)
-rw-r--r--ext/simplexml/simplexml.c2
-rw-r--r--ext/simplexml/tests/bug40451.phpt22
2 files changed, 23 insertions, 1 deletions
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c
index 6695f47301..603d1c5f8a 100644
--- a/ext/simplexml/simplexml.c
+++ b/ext/simplexml/simplexml.c
@@ -1526,7 +1526,7 @@ SXE_METHOD(addAttribute)
node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
- if (node->type != XML_ELEMENT_NODE) {
+ if (node && node->type != XML_ELEMENT_NODE) {
node = node->parent;
}
diff --git a/ext/simplexml/tests/bug40451.phpt b/ext/simplexml/tests/bug40451.phpt
new file mode 100644
index 0000000000..1a499a731d
--- /dev/null
+++ b/ext/simplexml/tests/bug40451.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Bug #40451 (addAttribute() may crash when used with non-existent child node)
+--FILE--
+<?php
+
+$string = <<<XML
+<?xml version="1.0"?>
+ <Host enable="true">
+ <Name>host.server.com</Name>
+ </Host>
+XML;
+
+$xml = simplexml_load_string($string);
+
+$add = $xml->addChild('Host');
+$add->Host->addAttribute('enable', 'true');
+
+echo "Done\n";
+?>
+--EXPECTF--
+Warning: SimpleXMLElement::addAttribute(): Unable to locate parent Element in %s on line %d
+Done