Skip to content

Commit d32b97a

Browse files
authored
Fix NULL pointer dereference with NULL content in legacy nodes in title getting (#15558)
1 parent 7ae7b4e commit d32b97a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

ext/dom/html_document.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,7 @@ static zend_string *dom_get_child_text_content(const xmlNode *node)
14671467

14681468
const xmlNode *text = node->children;
14691469
while (text != NULL) {
1470-
if (text->type == XML_TEXT_NODE || text->type == XML_CDATA_SECTION_NODE) {
1470+
if ((text->type == XML_TEXT_NODE || text->type == XML_CDATA_SECTION_NODE) && text->content != NULL) {
14711471
smart_str_appends(&content, (const char *) text->content);
14721472
}
14731473
text = text->next;

ext/dom/tests/modern/common/Document_title_getter.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ var_dump($dom->title);
4343
$dom = Dom\XMLDocument::createFromString("<root xmlns=\"http://www.w3.org/1999/xhtml\"><title>title\nhere</title></root>");
4444
var_dump($dom->title);
4545

46+
$dom = Dom\XMLDocument::createFromString("<root xmlns=\"http://www.w3.org/1999/xhtml\"><title/></root>");
47+
$dom->getElementsByTagName('title')[0]->appendChild($dom->importLegacyNode(new DOMText));
48+
var_dump($dom->title);
49+
4650
echo "=== SVG namespaced root ===\n";
4751

4852
$dom = Dom\XMLDocument::createFromString("<root xmlns=\"http://www.w3.org/1999/xhtml\"><title>title</title></root>");
@@ -72,6 +76,7 @@ string(0) ""
7276
string(2) "xz"
7377
string(2) "yw"
7478
string(10) "title here"
79+
string(0) ""
7580
=== SVG namespaced root ===
7681
string(5) "title"
7782
string(5) "title"

0 commit comments

Comments
 (0)