#41833 [NEW]: addChild() on a non-existent node, no node created, getName() segfaults

From: Date: Thu, 28 Jun 2007 02:18:58 +0000
Subject: #41833 [NEW]: addChild() on a non-existent node, no node created, getName() segfaults
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-114368@lists.php.net to get a copy of this message
From: hubert dot roksor at gmail dot com Operating system: PHP version: 5CVS-2007-06-28 (snap) PHP Bug Type: SimpleXML related Bug description: addChild() on a non-existent node, no node created, getName() segfaults Description: ------------ addChild() does not behave as expected(?) when used on a node that wasn't previously declared. In the example below, we initialize an empty tree, to which we attempt to add a new node at "/child/grandchild" without previously adding "child" to the tree. addChild() seems to operate on a temporary SimpleXMLElement and the changes are never applied to the original object/tree. I believe that this bug is also responsible of the segfault that happens if getName() is used on the temporary SimpleXMLElement. I was very tempted to file this bug as a reproducible crash, but decided to file it under SimpleXML in case it would help routing it to the maintainer faster. Tested on: PHP 5.2.4-dev (cli) (built: Jun 27 2007 20:04:30) WinXP libxml2 2.6.26 SimpleXML Revision: 1.151.2.22.2.29 PHP 5.2.2-pl1-gentoo (cli) (built: May 24 2007 00:26:35) libxml 2.6.27 SimpleXML Revision: 1.151.2.22.2.26 Reproduce code: --------------- <?php $xml = simplexml_load_string('<?xml version="1.0" encoding="utf-8" ?><root />'); $xml->child->addChild('grandchild'); echo $xml->asXML(); Expected result: ---------------- I expect SimpleXML to create "child" if it does not exist, then add "grandchild" to that node. The output should be: <?xml version="1.0" encoding="utf-8"?> <root><child><grandchild/></child></root> Actual result: -------------- Neither node is added to the tree. The output is: <?xml version="1.0" encoding="utf-8"?> <root/> -- Edit bug report at http://bugs.php.net/?id=41833&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41833&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41833&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41833&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=41833&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=41833&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=41833&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=41833&r=needscript Try newer version: http://bugs.php.net/fix.php?id=41833&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=41833&r=support Expected behavior: http://bugs.php.net/fix.php?id=41833&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=41833&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=41833&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=41833&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41833&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=41833&r=dst IIS Stability: http://bugs.php.net/fix.php?id=41833&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=41833&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=41833&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=41833&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=41833&r=mysqlcfg

« previous php.bugs (#114368) next »