Skip to content

Commit 19f73c5

Browse files
committed
Fix GH-21688: SEGV in C14N on empty HTMLDocument.
close GH-21693
1 parent 8972938 commit 19f73c5

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ PHP NEWS
1515
- DOM:
1616
. Fixed bug GH-21566 (Dom\XMLDocument::C14N() emits duplicate xmlns
1717
declarations after setAttributeNS()). (David Carlier)
18+
. Fixed bug GH-21688 (segmentation fault on empty HTMLDocument).
19+
(David Carlier)
1820

1921
- Iconv:
2022
. Fixed bug GH-17399 (iconv memory leak on bailout). (iliaal)

ext/dom/node.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2263,7 +2263,11 @@ static void dom_canonicalization(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{
22632263
}
22642264

22652265
zend_hash_init(&links, 0, NULL, NULL, false);
2266-
dom_relink_ns_decls(&links, xmlDocGetRootElement(docp));
2266+
xmlNodePtr root_element = xmlDocGetRootElement(docp);
2267+
2268+
if (root_element) {
2269+
dom_relink_ns_decls(&links, root_element);
2270+
}
22672271
} else if (!docp) {
22682272
/* Note: not triggerable with modern DOM */
22692273
zend_throw_error(NULL, "Node must be associated with a document");
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
GH-21688 (SEGV in C14N on empty HTMLDocument)
3+
--CREDITS--
4+
YuanchengJiang
5+
--EXTENSIONS--
6+
dom
7+
--FILE--
8+
<?php
9+
$dom = Dom\HTMLDocument::createEmpty();
10+
var_dump($dom->C14N());
11+
?>
12+
--EXPECT--
13+
string(0) ""

0 commit comments

Comments
 (0)