Skip to content

Commit 6d21598

Browse files
committed
Fix GH-17397: Assertion failure ext/dom/php_dom.c
The problem was that the property hash tables were not merging the correct ones, a stupid typo (or caused by merging). Closes GH-17406.
1 parent 7149362 commit 6d21598

File tree

5 files changed

+59
-80
lines changed

5 files changed

+59
-80
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ PHP NEWS
66
. Fixed bug GH-17234 (Numeric parent hook call fails with assertion).
77
(nielsdos)
88

9+
- DOM:
10+
. Fixed bug GH-17397 (Assertion failure ext/dom/php_dom.c). (nielsdos)
11+
912
- FTP:
1013
. Fixed bug GH-16800 (ftp functions can abort with EINTR). (nielsdos)
1114

ext/dom/php_dom.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ PHP_MINIT_FUNCTION(dom)
10801080
DOM_REGISTER_PROP_HANDLER(&dom_modern_attr_prop_handlers, "value", dom_attr_value_read, dom_attr_value_write);
10811081
DOM_REGISTER_PROP_HANDLER(&dom_modern_attr_prop_handlers, "ownerElement", dom_attr_owner_element_read, NULL);
10821082
DOM_REGISTER_PROP_HANDLER(&dom_modern_attr_prop_handlers, "specified", dom_attr_specified_read, NULL);
1083-
zend_hash_merge(&dom_modern_attr_prop_handlers, &dom_node_prop_handlers, NULL, false);
1083+
zend_hash_merge(&dom_modern_attr_prop_handlers, &dom_modern_node_prop_handlers, NULL, false);
10841084
DOM_OVERWRITE_PROP_HANDLER(&dom_modern_attr_prop_handlers, "nodeValue", dom_node_node_value_read, dom_node_node_value_write);
10851085
DOM_OVERWRITE_PROP_HANDLER(&dom_modern_attr_prop_handlers, "textContent", dom_node_text_content_read, dom_node_text_content_write);
10861086
zend_hash_add_new_ptr(&classes, dom_modern_attr_class_entry->name, &dom_modern_attr_prop_handlers);
@@ -1194,7 +1194,7 @@ PHP_MINIT_FUNCTION(dom)
11941194
DOM_REGISTER_PROP_HANDLER(&dom_modern_documenttype_prop_handlers, "publicId", dom_documenttype_public_id_read, NULL);
11951195
DOM_REGISTER_PROP_HANDLER(&dom_modern_documenttype_prop_handlers, "systemId", dom_documenttype_system_id_read, NULL);
11961196
DOM_REGISTER_PROP_HANDLER(&dom_modern_documenttype_prop_handlers, "internalSubset", dom_documenttype_internal_subset_read, NULL);
1197-
zend_hash_merge(&dom_modern_documenttype_prop_handlers, &dom_node_prop_handlers, NULL, false);
1197+
zend_hash_merge(&dom_modern_documenttype_prop_handlers, &dom_modern_node_prop_handlers, NULL, false);
11981198
zend_hash_add_new_ptr(&classes, dom_modern_documenttype_class_entry->name, &dom_modern_documenttype_prop_handlers);
11991199

12001200
dom_notation_class_entry = register_class_DOMNotation(dom_node_class_entry);

ext/dom/tests/gh17397.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
GH-17397 (Assertion failure ext/dom/php_dom.c)
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
$dom = Dom\HTMLDocument::createFromString('<!DOCTYPE html><html></html>');
8+
var_dump($dom->doctype->prefix);
9+
echo $dom->saveXml();
10+
?>
11+
--EXPECTF--
12+
Warning: Undefined property: Dom\DocumentType::$prefix in %s on line %d
13+
NULL
14+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
15+
<!DOCTYPE html>
16+
<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body></body></html>

ext/dom/tests/modern/spec/Document_implementation_createDocumentType.phpt

Lines changed: 28 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ foreach ($test_matrix as $test_item) {
2525

2626
?>
2727
--EXPECT--
28-
object(Dom\DocumentType)#3 (23) {
28+
object(Dom\DocumentType)#3 (19) {
2929
["name"]=>
3030
string(5) "qname"
3131
["entities"]=>
@@ -38,12 +38,14 @@ object(Dom\DocumentType)#3 (23) {
3838
string(6) "system"
3939
["internalSubset"]=>
4040
NULL
41+
["nodeType"]=>
42+
int(10)
4143
["nodeName"]=>
4244
string(5) "qname"
43-
["nodeValue"]=>
45+
["baseURI"]=>
4446
NULL
45-
["nodeType"]=>
46-
int(10)
47+
["isConnected"]=>
48+
bool(false)
4749
["parentNode"]=>
4850
NULL
4951
["parentElement"]=>
@@ -58,25 +60,15 @@ object(Dom\DocumentType)#3 (23) {
5860
NULL
5961
["nextSibling"]=>
6062
NULL
61-
["attributes"]=>
62-
NULL
63-
["isConnected"]=>
64-
bool(false)
65-
["namespaceURI"]=>
66-
NULL
67-
["prefix"]=>
68-
string(0) ""
69-
["localName"]=>
70-
NULL
71-
["baseURI"]=>
63+
["nodeValue"]=>
7264
NULL
7365
["textContent"]=>
7466
string(0) ""
7567
}
7668
<?xml version="1.0" encoding="UTF-8"?>
7769
<!DOCTYPE qname PUBLIC "public" "system">
7870

79-
object(Dom\DocumentType)#2 (23) {
71+
object(Dom\DocumentType)#2 (19) {
8072
["name"]=>
8173
string(5) "qname"
8274
["entities"]=>
@@ -89,12 +81,14 @@ object(Dom\DocumentType)#2 (23) {
8981
string(0) ""
9082
["internalSubset"]=>
9183
NULL
84+
["nodeType"]=>
85+
int(10)
9286
["nodeName"]=>
9387
string(5) "qname"
94-
["nodeValue"]=>
88+
["baseURI"]=>
9589
NULL
96-
["nodeType"]=>
97-
int(10)
90+
["isConnected"]=>
91+
bool(false)
9892
["parentNode"]=>
9993
NULL
10094
["parentElement"]=>
@@ -109,25 +103,15 @@ object(Dom\DocumentType)#2 (23) {
109103
NULL
110104
["nextSibling"]=>
111105
NULL
112-
["attributes"]=>
113-
NULL
114-
["isConnected"]=>
115-
bool(false)
116-
["namespaceURI"]=>
117-
NULL
118-
["prefix"]=>
119-
string(0) ""
120-
["localName"]=>
121-
NULL
122-
["baseURI"]=>
106+
["nodeValue"]=>
123107
NULL
124108
["textContent"]=>
125109
string(0) ""
126110
}
127111
<?xml version="1.0" encoding="UTF-8"?>
128112
<!DOCTYPE qname PUBLIC "public" "">
129113

130-
object(Dom\DocumentType)#1 (23) {
114+
object(Dom\DocumentType)#1 (19) {
131115
["name"]=>
132116
string(5) "qname"
133117
["entities"]=>
@@ -140,12 +124,14 @@ object(Dom\DocumentType)#1 (23) {
140124
string(6) "system"
141125
["internalSubset"]=>
142126
NULL
127+
["nodeType"]=>
128+
int(10)
143129
["nodeName"]=>
144130
string(5) "qname"
145-
["nodeValue"]=>
131+
["baseURI"]=>
146132
NULL
147-
["nodeType"]=>
148-
int(10)
133+
["isConnected"]=>
134+
bool(false)
149135
["parentNode"]=>
150136
NULL
151137
["parentElement"]=>
@@ -160,25 +146,15 @@ object(Dom\DocumentType)#1 (23) {
160146
NULL
161147
["nextSibling"]=>
162148
NULL
163-
["attributes"]=>
164-
NULL
165-
["isConnected"]=>
166-
bool(false)
167-
["namespaceURI"]=>
168-
NULL
169-
["prefix"]=>
170-
string(0) ""
171-
["localName"]=>
172-
NULL
173-
["baseURI"]=>
149+
["nodeValue"]=>
174150
NULL
175151
["textContent"]=>
176152
string(0) ""
177153
}
178154
<?xml version="1.0" encoding="UTF-8"?>
179155
<!DOCTYPE qname SYSTEM "system">
180156

181-
object(Dom\DocumentType)#4 (23) {
157+
object(Dom\DocumentType)#4 (19) {
182158
["name"]=>
183159
string(5) "qname"
184160
["entities"]=>
@@ -191,12 +167,14 @@ object(Dom\DocumentType)#4 (23) {
191167
string(0) ""
192168
["internalSubset"]=>
193169
NULL
170+
["nodeType"]=>
171+
int(10)
194172
["nodeName"]=>
195173
string(5) "qname"
196-
["nodeValue"]=>
174+
["baseURI"]=>
197175
NULL
198-
["nodeType"]=>
199-
int(10)
176+
["isConnected"]=>
177+
bool(false)
200178
["parentNode"]=>
201179
NULL
202180
["parentElement"]=>
@@ -211,17 +189,7 @@ object(Dom\DocumentType)#4 (23) {
211189
NULL
212190
["nextSibling"]=>
213191
NULL
214-
["attributes"]=>
215-
NULL
216-
["isConnected"]=>
217-
bool(false)
218-
["namespaceURI"]=>
219-
NULL
220-
["prefix"]=>
221-
string(0) ""
222-
["localName"]=>
223-
NULL
224-
["baseURI"]=>
192+
["nodeValue"]=>
225193
NULL
226194
["textContent"]=>
227195
string(0) ""

ext/dom/tests/modern/xml/DTDNamedNodeMap.phpt

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var_dump($doctype->notations["GIF"]);
2626

2727
?>
2828
--EXPECTF--
29-
object(Dom\DocumentType)#2 (24) {
29+
object(Dom\DocumentType)#2 (20) {
3030
["name"]=>
3131
string(4) "root"
3232
["entities"]=>
@@ -41,12 +41,16 @@ object(Dom\DocumentType)#2 (24) {
4141
string(105) "<!ENTITY test "entity is only for test purposes">
4242
<!ENTITY myimage PUBLIC "-" "mypicture.gif" NDATA GIF>
4343
"
44-
["nodeName"]=>
45-
string(4) "root"
46-
["nodeValue"]=>
47-
NULL
4844
["nodeType"]=>
4945
int(10)
46+
["nodeName"]=>
47+
string(4) "root"
48+
["baseURI"]=>
49+
string(%d) "%s"
50+
["isConnected"]=>
51+
bool(true)
52+
["ownerDocument"]=>
53+
string(22) "(object value omitted)"
5054
["parentNode"]=>
5155
string(22) "(object value omitted)"
5256
["parentElement"]=>
@@ -61,20 +65,8 @@ object(Dom\DocumentType)#2 (24) {
6165
NULL
6266
["nextSibling"]=>
6367
string(22) "(object value omitted)"
64-
["attributes"]=>
65-
NULL
66-
["isConnected"]=>
67-
bool(true)
68-
["ownerDocument"]=>
69-
string(22) "(object value omitted)"
70-
["namespaceURI"]=>
71-
NULL
72-
["prefix"]=>
73-
string(0) ""
74-
["localName"]=>
68+
["nodeValue"]=>
7569
NULL
76-
["baseURI"]=>
77-
string(%d) "%s"
7870
["textContent"]=>
7971
NULL
8072
}

0 commit comments

Comments
 (0)