Skip to content

Fix GH-15570: Segmentation fault (access null pointer) in ext/dom/html5_serializer.c #15572

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

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
4 changes: 2 additions & 2 deletions ext/dom/html5_serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ static zend_result dom_html5_serialize_text_node(dom_html5_serialize_context *ct
return SUCCESS;
}

if (node->parent->type == XML_ELEMENT_NODE && php_dom_ns_is_fast(node->parent, php_dom_ns_is_html_magic_token)) {
const xmlNode *parent = node->parent;
const xmlNode *parent = node->parent;
if (parent != NULL && parent->type == XML_ELEMENT_NODE && php_dom_ns_is_fast(parent, php_dom_ns_is_html_magic_token)) {
size_t name_length = strlen((const char *) parent->name);
/* Spec tells us to only emit noscript content as-is if scripting is enabled.
* However, the user agent (PHP) does not support (JS) scripting.
Expand Down
19 changes: 19 additions & 0 deletions ext/dom/tests/gh15570.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
GH-15570 (Segmentation fault (access null pointer) in ext/dom/html5_serializer.c)
--CREDITS--
YuanchengJiang
--EXTENSIONS--
dom
--FILE--
<?php
$html = <<<HTML
<head>
</html>
HTML;
$dom = Dom\HTMLDocument::createFromString($html, LIBXML_NOERROR);
$a = $dom->head->firstChild->cloneNode(false);
var_dump($dom->saveHTML($a));
?>
--EXPECT--
string(1) "
"
Loading