Skip to content

Commit ee68c22

Browse files
tstarlingnielsdos
authored andcommittedJun 5, 2023
Don't add 1 when calling xmlNodeSetContent()
The length is passed to xmlStrndup(), which also adds 1, and adds a null terminator past the end. It worked because the length is not actually stored. Strings in libxml2 are null terminated. Passing the length just avoids a call to strlen().
1 parent 74910b1 commit ee68c22

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed
 

‎ext/dom/characterdata.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ int dom_characterdata_data_write(dom_object *obj, zval *newval)
7070
return FAILURE;
7171
}
7272

73-
xmlNodeSetContentLen(nodep, (xmlChar *) ZSTR_VAL(str), ZSTR_LEN(str) + 1);
73+
xmlNodeSetContentLen(nodep, (xmlChar *) ZSTR_VAL(str), ZSTR_LEN(str));
7474

7575
zend_string_release_ex(str, 0);
7676
return SUCCESS;

‎ext/dom/node.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ int dom_node_node_value_write(dom_object *obj, zval *newval)
185185
case XML_COMMENT_NODE:
186186
case XML_CDATA_SECTION_NODE:
187187
case XML_PI_NODE:
188-
xmlNodeSetContentLen(nodep, (xmlChar *) ZSTR_VAL(str), ZSTR_LEN(str) + 1);
188+
xmlNodeSetContentLen(nodep, (xmlChar *) ZSTR_VAL(str), ZSTR_LEN(str));
189189
break;
190190
default:
191191
break;

‎ext/dom/processinginstruction.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ int dom_processinginstruction_data_write(dom_object *obj, zval *newval)
130130

131131
php_libxml_invalidate_node_list_cache_from_doc(nodep->doc);
132132

133-
xmlNodeSetContentLen(nodep, (xmlChar *) ZSTR_VAL(str), ZSTR_LEN(str) + 1);
133+
xmlNodeSetContentLen(nodep, (xmlChar *) ZSTR_VAL(str), ZSTR_LEN(str));
134134

135135
zend_string_release_ex(str, 0);
136136
return SUCCESS;

0 commit comments

Comments
 (0)