From: Antony Dovgal Date: Mon, 12 Feb 2007 21:13:01 +0000 (+0000) Subject: MFB: #40451 (addAttribute() may crash when used with non-existent child node) X-Git-Tag: RELEASE_1_0_1~273 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=41e02dad89fa6d28f3944d3f81453cff595ce6b4;p=php MFB: #40451 (addAttribute() may crash when used with non-existent child node) --- diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index ef8f675302..9d4385a3ae 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1586,7 +1586,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..949dc87575 --- /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((binary)$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