Skip to content

Commit c8c0e97

Browse files
committed
Prevent SimpleXML from silently modifying types of variables that are
assigned to its objects. Implementation notes for overloaded object modules: - If you return a zval which is not otherwise referenced by the extension or the engine's symbol table, its reference count should be 0. - If you receive a value zval in write_property/write_dimension, you may only modify it if its reference count is 1. Otherwise, you must create a copy of that zval before making any changes. You should NOT modify the reference count of the value passed to you. Have fun!
1 parent d91fc5f commit c8c0e97

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

ext/simplexml/simplexml.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,25 @@ static zval * sxe_dimension_read(zval *object, zval *offset, int type TSRMLS_DC)
274274
static void
275275
change_node_zval(xmlNodePtr node, zval *value)
276276
{
277+
zval value_copy;
278+
277279
switch (Z_TYPE_P(value)) {
278280
case IS_LONG:
279281
case IS_BOOL:
280282
case IS_DOUBLE:
281283
case IS_NULL:
284+
if (value->refcount > 1) {
285+
value_copy = *value;
286+
zval_copy_ctor(&value_copy);
287+
value = &value_copy;
288+
}
282289
convert_to_string(value);
290+
/* break missing intentionally */
283291
case IS_STRING:
284292
xmlNodeSetContentLen(node, Z_STRVAL_P(value), Z_STRLEN_P(value));
293+
if (value == &value_copy) {
294+
zval_dtor(value);
295+
}
285296
break;
286297
default:
287298
php_error(E_WARNING, "It is not possible to assign complex types to nodes");

0 commit comments

Comments
 (0)