]> granicus.if.org Git - php/commitdiff
- Fixed bug #51615 (PHP crash with wrong HTML in SimpleXML)
authorFelipe Pena <felipe@php.net>
Tue, 20 Apr 2010 16:24:21 +0000 (16:24 +0000)
committerFelipe Pena <felipe@php.net>
Tue, 20 Apr 2010 16:24:21 +0000 (16:24 +0000)
NEWS
ext/simplexml/simplexml.c
ext/simplexml/tests/bug51615.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 1c65adef2152c1ab496a464b28370e5d87a9c860..fb21796df7f2e6790e6f1de477d8ca74f488797e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,7 @@ PHP                                                                        NEWS
 - Fixed a NULL pointer dereference when processing invalid XML-RPC
   requests (Fixes CVE-2010-0397, bug #51288). (Raphael Geissert)
 
+- Fixed bug #51615 (PHP crash with wrong HTML in SimpleXML). (Felipe)
 - Fixed bug #51609 (pg_copy_to: Invalid results when using fourth parameter).
   (Felipe)
 - Fixed bug #51608 (pg_copy_to: WARNING: nonstandard use of \\ in a string
index 7a0a777da48d409ecbabf4f590975ad8d1f4bb55..d4a17cf6b7bf94284a9532d406569a9803ca5085 100644 (file)
@@ -969,9 +969,14 @@ static void sxe_dimension_delete(zval *object, zval *offset TSRMLS_DC)
 static inline char * sxe_xmlNodeListGetString(xmlDocPtr doc, xmlNodePtr list, int inLine)
 {
        xmlChar *tmp = xmlNodeListGetString(doc, list, inLine);
-       char    *res = estrdup((char*)tmp);
-
-       xmlFree(tmp);
+       char    *res;
+       
+       if (tmp) {
+               res = estrdup((char*)tmp);
+               xmlFree(tmp);
+       } else {
+               res = STR_EMPTY_ALLOC();
+       }
        
        return res;
 }
diff --git a/ext/simplexml/tests/bug51615.phpt b/ext/simplexml/tests/bug51615.phpt
new file mode 100644 (file)
index 0000000..c5572f5
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+Bug #51615 (PHP crash with wrong HTML in SimpleXML)
+--SKIPIF--
+<?php if (!extension_loaded("simplexml")) print "skip"; ?>
+--FILE--
+<?php
+
+$dom = new DOMDocument;
+$dom->loadHTML('<span title=""y">x</span><span title=""z">x</span>');
+$html = simplexml_import_dom($dom);
+
+foreach ($html->body->span as $obj) {
+       var_dump((string)$obj->title);
+}
+
+?>
+--EXPECTF--
+Warning: DOMDocument::loadHTML(): error parsing attribute name in Entity, line: 1 in %s on line %d
+
+Warning: DOMDocument::loadHTML(): error parsing attribute name in Entity, line: 1 in %s on line %d
+string(0) ""
+string(0) ""