Skip to content

Commit d14ae9b

Browse files
committed
Zend: Fix string leak in zend_update_property_string{,l} on write failure
The four zend_update_{,static_}property_string{,l} helpers built a zval with refcount 0 and called the write path, expecting the consumer to absorb the only reference. Failure paths (readonly, asymmetric visibility, type mismatch, magic __set throw) returned without consuming the value, leaking the zend_string at refcount 0. Build the zval normally and zval_ptr_dtor it after the write.
1 parent bba2dc3 commit d14ae9b

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

Zend/zend_API.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4984,8 +4984,8 @@ ZEND_API void zend_update_property_string(const zend_class_entry *scope, zend_ob
49844984
zval tmp;
49854985

49864986
ZVAL_STRING(&tmp, value);
4987-
Z_SET_REFCOUNT(tmp, 0);
49884987
zend_update_property(scope, object, name, name_length, &tmp);
4988+
zval_ptr_dtor(&tmp);
49894989
}
49904990
/* }}} */
49914991

@@ -4994,8 +4994,8 @@ ZEND_API void zend_update_property_stringl(const zend_class_entry *scope, zend_o
49944994
zval tmp;
49954995

49964996
ZVAL_STRINGL(&tmp, value, value_len);
4997-
Z_SET_REFCOUNT(tmp, 0);
49984997
zend_update_property(scope, object, name, name_length, &tmp);
4998+
zval_ptr_dtor(&tmp);
49994999
}
50005000
/* }}} */
50015001

@@ -5085,8 +5085,9 @@ ZEND_API zend_result zend_update_static_property_string(zend_class_entry *scope,
50855085
zval tmp;
50865086

50875087
ZVAL_STRING(&tmp, value);
5088-
Z_SET_REFCOUNT(tmp, 0);
5089-
return zend_update_static_property(scope, name, name_length, &tmp);
5088+
zend_result retval = zend_update_static_property(scope, name, name_length, &tmp);
5089+
zval_ptr_dtor(&tmp);
5090+
return retval;
50905091
}
50915092
/* }}} */
50925093

@@ -5095,8 +5096,9 @@ ZEND_API zend_result zend_update_static_property_stringl(zend_class_entry *scope
50955096
zval tmp;
50965097

50975098
ZVAL_STRINGL(&tmp, value, value_len);
5098-
Z_SET_REFCOUNT(tmp, 0);
5099-
return zend_update_static_property(scope, name, name_length, &tmp);
5099+
zend_result retval = zend_update_static_property(scope, name, name_length, &tmp);
5100+
zval_ptr_dtor(&tmp);
5101+
return retval;
51005102
}
51015103
/* }}} */
51025104

0 commit comments

Comments
 (0)