Skip to content

Commit 525aeff

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix GH-17500: Segfault with requesting nodeName on nameless doctype
2 parents 2952e16 + 82d71a8 commit 525aeff

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ PHP NEWS
2222
. Fixed bug GH-17486 (Incorrect error line numbers reported in
2323
Dom\HTMLDocument::createFromString). (nielsdos)
2424
. Fixed bug GH-17481 (UTF-8 corruption in \Dom\HTMLDocument). (nielsdos)
25+
. Fixed bug GH-17500 (Segfault with requesting nodeName on nameless doctype).
26+
(nielsdos)
2527

2628
- Enchant:
2729
. Fix crashes in enchant when passing null bytes. (nielsdos)

ext/dom/node.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,17 @@ zend_result dom_node_node_name_read(dom_object *obj, zval *retval)
102102
}
103103
case XML_DOCUMENT_TYPE_NODE:
104104
case XML_DTD_NODE:
105+
if (nodep->name) {
106+
ZVAL_STRING(retval, (const char *) nodep->name);
107+
} else {
108+
ZVAL_EMPTY_STRING(retval);
109+
}
110+
break;
105111
case XML_PI_NODE:
106112
case XML_ENTITY_DECL:
107113
case XML_ENTITY_REF_NODE:
108114
case XML_NOTATION_NODE:
109-
ZVAL_STRING(retval, (char *) nodep->name);
115+
ZVAL_STRING(retval, (const char *) nodep->name);
110116
break;
111117
case XML_CDATA_SECTION_NODE:
112118
ZVAL_STRING(retval, "#cdata-section");

ext/dom/tests/gh17500.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
GH-17500 (Segfault with requesting nodeName on nameless doctype)
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$doc = new DOMDocument();
9+
$doc->loadHTML("<!DOCTYPE>", LIBXML_NOERROR);
10+
var_dump($doc->doctype->nodeName);
11+
12+
?>
13+
--EXPECT--
14+
string(0) ""

0 commit comments

Comments
 (0)