Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GH-17500: Segfault with requesting nodeName on nameless doctype #17501

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ext/dom/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,17 @@ int dom_node_node_name_read(dom_object *obj, zval *retval)
}
case XML_DOCUMENT_TYPE_NODE:
case XML_DTD_NODE:
if (nodep->name) {
ZVAL_STRING(retval, (const char *) nodep->name);
} else {
ZVAL_EMPTY_STRING(retval);
}
break;
case XML_PI_NODE:
case XML_ENTITY_DECL:
case XML_ENTITY_REF_NODE:
case XML_NOTATION_NODE:
ZVAL_STRING(retval, (char *) nodep->name);
ZVAL_STRING(retval, (const char *) nodep->name);
break;
case XML_CDATA_SECTION_NODE:
ZVAL_STRING(retval, "#cdata-section");
Expand Down
14 changes: 14 additions & 0 deletions ext/dom/tests/gh17500.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
GH-17500 (Segfault with requesting nodeName on nameless doctype)
--EXTENSIONS--
dom
--FILE--
<?php

$doc = new DOMDocument();
$doc->loadHTML("<!DOCTYPE>", LIBXML_NOERROR);
var_dump($doc->doctype->nodeName);

?>
--EXPECT--
string(0) ""
Loading