@@ -990,7 +990,7 @@ static bool dom_node_check_legacy_insertion_validity(xmlNodePtr parentp, xmlNode
990
990
PHP_METHOD (DOMNode , insertBefore )
991
991
{
992
992
zval * id , * node , * ref = NULL ;
993
- xmlNodePtr child , new_child , parentp , refp ;
993
+ xmlNodePtr child , new_child , parentp , refp = NULL ;
994
994
dom_object * intern , * childobj , * refpobj ;
995
995
int ret , stricterror ;
996
996
@@ -1015,19 +1015,21 @@ PHP_METHOD(DOMNode, insertBefore)
1015
1015
RETURN_FALSE ;
1016
1016
}
1017
1017
1018
- if (child -> doc == NULL && parentp -> doc != NULL ) {
1019
- dom_set_document_ref_pointers (child , intern -> document );
1020
- }
1021
-
1022
- php_libxml_invalidate_node_list_cache (intern -> document );
1023
-
1024
1018
if (ref != NULL ) {
1025
1019
DOM_GET_OBJ (refp , ref , xmlNodePtr , refpobj );
1026
1020
if (refp -> parent != parentp ) {
1027
1021
php_dom_throw_error (NOT_FOUND_ERR , stricterror );
1028
1022
RETURN_FALSE ;
1029
1023
}
1024
+ }
1025
+
1026
+ if (child -> doc == NULL && parentp -> doc != NULL ) {
1027
+ dom_set_document_ref_pointers (child , intern -> document );
1028
+ }
1030
1029
1030
+ php_libxml_invalidate_node_list_cache (intern -> document );
1031
+
1032
+ if (ref != NULL ) {
1031
1033
if (child -> parent != NULL ) {
1032
1034
xmlUnlinkNode (child );
1033
1035
}
@@ -1173,6 +1175,13 @@ PHP_METHOD(DOMNode, replaceChild)
1173
1175
RETURN_FALSE ;
1174
1176
}
1175
1177
1178
+ /* This is already disallowed by libxml, but we should check it here to avoid
1179
+ * breaking assumptions and assertions. */
1180
+ if ((oldchild -> type == XML_ATTRIBUTE_NODE ) != (newchild -> type == XML_ATTRIBUTE_NODE )) {
1181
+ php_dom_throw_error (HIERARCHY_REQUEST_ERR , stricterror );
1182
+ RETURN_FALSE ;
1183
+ }
1184
+
1176
1185
if (oldchild -> parent != nodep ) {
1177
1186
php_dom_throw_error (NOT_FOUND_ERR , stricterror );
1178
1187
RETURN_FALSE ;
0 commit comments