From: Antony Dovgal Date: Mon, 12 Feb 2007 21:06:29 +0000 (+0000) Subject: fix #40451 (addAttribute() may crash when used with non-existent child node) X-Git-Tag: php-5.2.2RC1~418 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2c31b1e194adc746597eb9ab2310e87e01bf86d4;p=php fix #40451 (addAttribute() may crash when used with non-existent child node) --- 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-- + + + host.server.com + +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