Fix NULL pointer dereference with NULL content in legacy nodes in title getting (#15558)

This commit is contained in:
Niels Dossche 2024-08-23 19:38:13 +02:00 committed by GitHub
parent 7ae7b4e388
commit d32b97a1c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View file

@ -1467,7 +1467,7 @@ static zend_string *dom_get_child_text_content(const xmlNode *node)
const xmlNode *text = node->children; const xmlNode *text = node->children;
while (text != NULL) { while (text != NULL) {
if (text->type == XML_TEXT_NODE || text->type == XML_CDATA_SECTION_NODE) { if ((text->type == XML_TEXT_NODE || text->type == XML_CDATA_SECTION_NODE) && text->content != NULL) {
smart_str_appends(&content, (const char *) text->content); smart_str_appends(&content, (const char *) text->content);
} }
text = text->next; text = text->next;

View file

@ -43,6 +43,10 @@ var_dump($dom->title);
$dom = Dom\XMLDocument::createFromString("<root xmlns=\"http://www.w3.org/1999/xhtml\"><title>title\nhere</title></root>"); $dom = Dom\XMLDocument::createFromString("<root xmlns=\"http://www.w3.org/1999/xhtml\"><title>title\nhere</title></root>");
var_dump($dom->title); var_dump($dom->title);
$dom = Dom\XMLDocument::createFromString("<root xmlns=\"http://www.w3.org/1999/xhtml\"><title/></root>");
$dom->getElementsByTagName('title')[0]->appendChild($dom->importLegacyNode(new DOMText));
var_dump($dom->title);
echo "=== SVG namespaced root ===\n"; echo "=== SVG namespaced root ===\n";
$dom = Dom\XMLDocument::createFromString("<root xmlns=\"http://www.w3.org/1999/xhtml\"><title>title</title></root>"); $dom = Dom\XMLDocument::createFromString("<root xmlns=\"http://www.w3.org/1999/xhtml\"><title>title</title></root>");
@ -72,6 +76,7 @@ string(0) ""
string(2) "xz" string(2) "xz"
string(2) "yw" string(2) "yw"
string(10) "title here" string(10) "title here"
string(0) ""
=== SVG namespaced root === === SVG namespaced root ===
string(5) "title" string(5) "title"
string(5) "title" string(5) "title"