Skip to content

Commit 690ce6d

Browse files
committed
Fix phpGH-15570: Segmentation fault (access null pointer) in ext/dom/html5_serializer.c
Closes phpGH-15572.
1 parent 2ca4f31 commit 690ce6d

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ PHP NEWS
2424
- DOM:
2525
. Fixed bug GH-15551 (Segmentation fault (access null pointer) in
2626
ext/dom/xml_common.h). (nielsdos)
27+
. Fixed bug GH-15570 (Segmentation fault (access null pointer) in
28+
ext/dom/html5_serializer.c). (nielsdos)
2729

2830
- FPM:
2931
. Added memory peak to the scoreboard / status page. (Flávio Heleno)

ext/dom/html5_serializer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ static zend_result dom_html5_serialize_text_node(dom_html5_serialize_context *ct
137137
return SUCCESS;
138138
}
139139

140-
if (node->parent->type == XML_ELEMENT_NODE && php_dom_ns_is_fast(node->parent, php_dom_ns_is_html_magic_token)) {
141-
const xmlNode *parent = node->parent;
140+
const xmlNode *parent = node->parent;
141+
if (parent != NULL && parent->type == XML_ELEMENT_NODE && php_dom_ns_is_fast(parent, php_dom_ns_is_html_magic_token)) {
142142
size_t name_length = strlen((const char *) parent->name);
143143
/* Spec tells us to only emit noscript content as-is if scripting is enabled.
144144
* However, the user agent (PHP) does not support (JS) scripting.

ext/dom/tests/gh15570.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
GH-15570 (Segmentation fault (access null pointer) in ext/dom/html5_serializer.c)
3+
--CREDITS--
4+
YuanchengJiang
5+
--EXTENSIONS--
6+
dom
7+
--FILE--
8+
<?php
9+
$html = <<<HTML
10+
<head>
11+
</html>
12+
HTML;
13+
$dom = Dom\HTMLDocument::createFromString($html, LIBXML_NOERROR);
14+
$a = $dom->head->firstChild->cloneNode(false);
15+
var_dump($dom->saveHTML($a));
16+
?>
17+
--EXPECT--
18+
string(1) "
19+
"

0 commit comments

Comments
 (0)