php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19266 Segfault on append_child()
Submitted: 2002-09-06 10:17 UTC Modified: 2002-09-09 15:22 UTC
From: pavlomr at hotmail dot com Assigned: chregu (profile)
Status: Closed Package: DOM XML related
PHP Version: 4CVS-2002-09-06 OS: SuSE Linux 7.3
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: pavlomr at hotmail dot com
New email:
PHP Version: OS:

 

 [2002-09-06 10:17 UTC] pavlomr at hotmail dot com
This bug corelates with #18197
Prehistory:
libxml-1.8.15, libxml2-2.4.23
'./configure' \
'--prefix=/usr/share' \
'--datadir=/usr/share/php' \
'--bindir=/usr/bin' \
'--libdir=/usr/share' \
'--with-config-file-path=/etc' \
'--with-exec-dir=/usr/lib/php/bin' \
'--with-mysql=/usr' \
'--with-informix' \
'--with-gd=yes' \
'--enable-gd-native-ttf' \
'--enable-gd-imgstrttf' \
'--with-tiff-dir=/usr' \
'--with-jpeg-dir=/usr' \
'--with-png-dir=/usr' \
'--with-xpm-dir=/usr/X11R6' \
'--with-ldap=yes' \
'--with-zlib' \
'--with-zlib-dir' \
'--with-bz2' \
'--with-gmp' \
'--with-xml' \
'--with-xmlrpc' \
'--with-xslt-sablot' \
'--with-expat-dir=/usr' \
'--with-dom' \
'--with-dom-xslt' \
'--with-dom-exslt' \
'--with-ttf' \
'--with-t1lib' \
'--with-mcal=/usr' \
'--with-imap=yes' \
'--with-sablot' \
'--with-sablot-js' \
'--with-readline' \
'--with-ftp' \
'--with-ndbm' \
'--with-gdbm' \
'--with-mcrypt' \
'--with-gettext' \
'--with-mm' \
'--with-gd=yes' \
'--with-qtdom=/usr/lib/qt2' \
'--enable-versioning' \
'--enable-yp' \
'--enable-bcmath' \
'--enable-trans-sid' \
'--enable-inline-optimization' \
'--enable-track-vars' \
'--enable-magic-quotes' \
'--enable-safe-mode' \
'--enable-sockets' \
'--enable-sysvsem' \
'--enable-sysvshm' \
'--enable-shmop' \
'--enable-calendar' \
'--enable-mbstring' \
'--enable-mbstr-enc-trans' \
'--enable-exif' \
'--enable-ftp' \
'--enable-memory-limit' \
'--enable-wddx' \
'--enable-filepro' \
'--enable-dbase' \
'--enable-ctype' \
'--enable-force-cgi-redirect' \
'--enable-discard-path' \
'--enable-sigchild' \
'--with-openssl' \
'--with-imap-ssl' \
'--with-gd=yes' \
'--with-apxs=/usr/sbin/apxs' \
'--with-pgsql=/usr' \
'--with-snmp' \
'--with-iconv' \
'--with-iconv-dir' \
'i686-suse-linux' \
"$@"

script bug.php:
<?php
$x1="<?xml version='1.0' encoding='iso8859-1' ?>
<root1 xml:lang='de' xmlns:xml='http://www.w3.org/XML/1998/namespace'>
<node xml:lang='en'>1 EN node</node>
<node xml:lang='de'>1 DE node</node>
<node>1 Default node</node>
</root1>
";
$x2="<?xml version='1.0' encoding='iso8859-1' ?>
<root2 xml:lang='en' xmlns:xml='http://www.w3.org/XML/1998/namespace'>
<node xml:lang='en'>2 EN node</node>
<node xml:lang='de'>2 DE node</node>
<node> 2 Default node</node>
</root2>
";
$d1=domxml_open_mem($x1);
$d2=domxml_open_mem($x2);

$r1=$d1->document_element();
$r2=$d2->document_element();
$r1->append_child($r2);

echo $d1->dump_mem();

?>

produce output:
<?xml version="1.0" encoding="iso8859-1"?>
<root1 xml:lang="de">
<node xml:lang="en">1 EN node</node>
<node xml:lang="de">1 DE node</node>
<node>1 Default node</node>
<root2 xml:lang="en">
<node xml:lang="en">2 EN node</node>
<node xml:lang="de">2 DE node</node>
<node> 2 Default node</node>
</root2></root1>
Segmentation fault

Script segfaults WITH AND WITHOUT xmlns:xml declaration

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-09-09 14:58 UTC] chregu@php.net
Hi

yep, this segfaults...

but, you shouldn't append nodes from one document to another document for the time being.

But you can use: 
$r1->append_child($r2->clone_node(1)); 

which works fine on my system

chregu
 [2002-09-09 15:03 UTC] chregu@php.net
Hi 

checked with the W3-DOM standard (http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1950641247). It's forbidden, what you are trying to do: 

"WRONG_DOCUMENT_ERR: Raised if newChild was created from a different document than the one that created this node."

I'll write a check into the method, so that it doesn't segfault, but return an error

chregu
 [2002-09-09 15:22 UTC] chregu@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 14 05:01:30 2024 UTC