@@ -50,6 +50,10 @@ PHP_METHOD(DOMElement, __construct)
5050 RETURN_THROWS ();
5151 }
5252
53+ if (dom_throw_if_node_read_only (Z_DOMOBJ_P (ZEND_THIS )-> document , dom_object_get_node (Z_DOMOBJ_P (ZEND_THIS )))) {
54+ return ;
55+ }
56+
5357 name_valid = xmlValidateName (BAD_CAST name , 0 );
5458 if (name_valid != 0 ) {
5559 php_dom_throw_error (INVALID_CHARACTER_ERR , true);
@@ -429,6 +433,10 @@ PHP_METHOD(DOMElement, setAttribute)
429433
430434 DOM_GET_OBJ (nodep , ZEND_THIS , xmlNodePtr , intern );
431435
436+ if (dom_throw_if_node_read_only (intern -> document , nodep )) {
437+ RETURN_FALSE ;
438+ }
439+
432440 if (php_dom_follow_spec_intern (intern )) {
433441 xmlChar * name_processed = BAD_CAST name ;
434442 if (php_dom_ns_is_html_and_document_is_html (nodep )) {
@@ -619,6 +627,10 @@ PHP_METHOD(DOMElement, removeAttribute)
619627
620628 DOM_GET_OBJ (nodep , ZEND_THIS , xmlNodePtr , intern );
621629
630+ if (dom_throw_if_node_read_only (intern -> document , nodep )) {
631+ RETURN_FALSE ;
632+ }
633+
622634 attrp = dom_get_attribute_or_nsdecl (intern , nodep , BAD_CAST name , name_len );
623635 if (attrp == NULL ) {
624636 RETURN_FALSE ;
@@ -640,6 +652,10 @@ PHP_METHOD(Dom_Element, removeAttribute)
640652
641653 DOM_GET_OBJ (nodep , ZEND_THIS , xmlNodePtr , intern );
642654
655+ if (dom_throw_if_node_read_only (intern -> document , nodep )) {
656+ RETURN_THROWS ();
657+ }
658+
643659 attrp = dom_get_attribute_or_nsdecl (intern , nodep , BAD_CAST name , name_len );
644660 if (attrp != NULL ) {
645661 dom_remove_attribute (nodep , attrp , intern -> document );
@@ -699,6 +715,10 @@ static void dom_element_set_attribute_node_common(INTERNAL_FUNCTION_PARAMETERS,
699715 DOM_GET_OBJ (nodep , id , xmlNodePtr , intern );
700716 DOM_GET_OBJ (attrp , node , xmlAttrPtr , attrobj );
701717
718+ if (dom_throw_if_node_read_only (intern -> document , nodep ) || dom_throw_if_node_read_only (attrobj -> document , (xmlNodePtr ) attrp )) {
719+ RETURN_FALSE ;
720+ }
721+
702722 /* ZPP Guarantees that a DOMAttr class is given, as it is converted to a xmlAttr
703723 * to pass to libxml (see http://www.xmlsoft.org/html/libxml-tree.html#xmlAttr)
704724 * if it is not of type XML_ATTRIBUTE_NODE it indicates a bug somewhere */
@@ -795,6 +815,10 @@ static void dom_element_remove_attribute_node(INTERNAL_FUNCTION_PARAMETERS, zend
795815
796816 ZEND_ASSERT (attrp -> type == XML_ATTRIBUTE_NODE );
797817
818+ if (dom_throw_if_node_read_only (intern -> document , nodep )) {
819+ RETURN_FALSE ;
820+ }
821+
798822 if (attrp -> parent != nodep ) {
799823 php_dom_throw_error (NOT_FOUND_ERR , dom_get_strict_error (intern -> document ));
800824 RETURN_FALSE ;
@@ -1095,6 +1119,10 @@ PHP_METHOD(DOMElement, setAttributeNS)
10951119
10961120 DOM_GET_OBJ (elemp , id , xmlNodePtr , intern );
10971121
1122+ if (dom_throw_if_node_read_only (intern -> document , elemp )) {
1123+ return ;
1124+ }
1125+
10981126 if (php_dom_follow_spec_intern (intern )) {
10991127 dom_set_attribute_ns_modern (intern , elemp , uri , name , value );
11001128 } else {
@@ -1185,6 +1213,10 @@ PHP_METHOD(DOMElement, removeAttributeNS)
11851213
11861214 DOM_GET_OBJ (nodep , id , xmlNodePtr , intern );
11871215
1216+ if (dom_throw_if_node_read_only (intern -> document , nodep )) {
1217+ return ;
1218+ }
1219+
11881220 bool follow_spec = php_dom_follow_spec_intern (intern );
11891221 if (follow_spec && uri_len == 0 ) {
11901222 uri = NULL ;
@@ -1408,6 +1440,10 @@ PHP_METHOD(DOMElement, setIdAttribute)
14081440
14091441 DOM_GET_OBJ (nodep , id , xmlNodePtr , intern );
14101442
1443+ if (dom_throw_if_node_read_only (intern -> document , nodep )) {
1444+ return ;
1445+ }
1446+
14111447 attrp = xmlHasNsProp (nodep , BAD_CAST name , NULL );
14121448 if (attrp == NULL || attrp -> type == XML_ATTRIBUTE_DECL ) {
14131449 php_dom_throw_error (NOT_FOUND_ERR , dom_get_strict_error (intern -> document ));
@@ -1437,6 +1473,10 @@ PHP_METHOD(DOMElement, setIdAttributeNS)
14371473
14381474 DOM_GET_OBJ (elemp , id , xmlNodePtr , intern );
14391475
1476+ if (dom_throw_if_node_read_only (intern -> document , elemp )) {
1477+ return ;
1478+ }
1479+
14401480 attrp = xmlHasNsProp (elemp , BAD_CAST name , BAD_CAST uri );
14411481 if (attrp == NULL || attrp -> type == XML_ATTRIBUTE_DECL ) {
14421482 php_dom_throw_error (NOT_FOUND_ERR , dom_get_strict_error (intern -> document ));
@@ -1465,6 +1505,10 @@ static void dom_element_set_id_attribute_node(INTERNAL_FUNCTION_PARAMETERS, zend
14651505 DOM_GET_OBJ (nodep , id , xmlNodePtr , intern );
14661506 DOM_GET_OBJ (attrp , node , xmlAttrPtr , attrobj );
14671507
1508+ if (dom_throw_if_node_read_only (intern -> document , nodep )) {
1509+ return ;
1510+ }
1511+
14681512 if (attrp -> parent != nodep ) {
14691513 php_dom_throw_error (NOT_FOUND_ERR , dom_get_strict_error (intern -> document ));
14701514 } else {
@@ -1665,6 +1709,10 @@ static void dom_element_insert_adjacent_element(INTERNAL_FUNCTION_PARAMETERS, ze
16651709 DOM_GET_THIS_OBJ (thisp , id , xmlNodePtr , this_intern );
16661710 DOM_GET_OBJ (otherp , element_zval , xmlNodePtr , other_intern );
16671711
1712+ if (dom_throw_if_node_read_only (this_intern -> document , thisp ) || dom_throw_if_node_read_only (other_intern -> document , otherp )) {
1713+ RETURN_NULL ();
1714+ }
1715+
16681716 xmlNodePtr result = dom_insert_adjacent (where , thisp , this_intern , otherp );
16691717 if (result == NULL ) {
16701718 RETURN_NULL ();
@@ -1741,6 +1789,10 @@ static void dom_element_insert_adjacent_text(INTERNAL_FUNCTION_PARAMETERS, zend_
17411789
17421790 DOM_GET_THIS_OBJ (thisp , id , xmlNodePtr , this_intern );
17431791
1792+ if (dom_throw_if_node_read_only (this_intern -> document , thisp )) {
1793+ return ;
1794+ }
1795+
17441796 if (UNEXPECTED (ZEND_SIZE_T_INT_OVFL (ZSTR_LEN (data )))) {
17451797 zend_argument_value_error (2 , "is too long" );
17461798 RETURN_THROWS ();
@@ -1809,6 +1861,10 @@ PHP_METHOD(Dom_Element, insertAdjacentHTML)
18091861
18101862 DOM_GET_THIS_OBJ (thisp , id , xmlNodePtr , this_intern );
18111863
1864+ if (dom_throw_if_node_read_only (this_intern -> document , thisp )) {
1865+ RETURN_THROWS ();
1866+ }
1867+
18121868 /* 1. We don't do injection sinks. */
18131869
18141870 /* 2. Let context be NULL */
@@ -1899,6 +1955,10 @@ PHP_METHOD(DOMElement, toggleAttribute)
18991955
19001956 DOM_GET_THIS_OBJ (thisp , id , xmlNodePtr , intern );
19011957
1958+ if (dom_throw_if_node_read_only (intern -> document , thisp )) {
1959+ RETURN_FALSE ;
1960+ }
1961+
19021962 /* Step 1 */
19031963 if (xmlValidateName (BAD_CAST qname , 0 ) != 0 ) {
19041964 php_dom_throw_error (INVALID_CHARACTER_ERR , true);
@@ -2177,6 +2237,10 @@ PHP_METHOD(Dom_Element, rename)
21772237 xmlNodePtr nodep ;
21782238 DOM_GET_THIS_OBJ (nodep , id , xmlNodePtr , intern );
21792239
2240+ if (dom_throw_if_node_read_only (intern -> document , nodep )) {
2241+ RETURN_THROWS ();
2242+ }
2243+
21802244 xmlChar * localname = NULL , * prefix = NULL ;
21812245 int errorcode = dom_validate_and_extract (namespace_uri , qualified_name , & localname , & prefix );
21822246 if (UNEXPECTED (errorcode != 0 )) {
0 commit comments