Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ PHP NEWS
. Fixed a crash in readline_info() when completion_append_character
contains a non-ASCII byte. (Weilin Du)

- Reflection:
. Fixed bug GH-24729 (Use-after-free in
ReflectionClass::setStaticPropertyValue() when the old value's destructor
unbinds the property). (Lazizbek Ergashev)

- SAPI:
. Fixed infinite loop in sapi_header_op() for headers of 4 GiB or more.
(Martin Mirchev)
Expand Down
13 changes: 2 additions & 11 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -4439,21 +4439,12 @@ ZEND_METHOD(ReflectionClass, setStaticPropertyValue)
RETURN_THROWS();
}

if (Z_ISREF_P(variable_ptr)) {
zend_reference *ref = Z_REF_P(variable_ptr);
variable_ptr = Z_REFVAL_P(variable_ptr);

if (!zend_verify_ref_assignable_zval(ref, value, 0)) {
return;
}
}

if (ZEND_TYPE_IS_SET(prop_info->type) && !zend_verify_property_type(prop_info, value, 0)) {
return;
}

zval_ptr_dtor(variable_ptr);
ZVAL_COPY(variable_ptr, value);
Z_TRY_ADDREF_P(value);
zend_assign_to_variable(variable_ptr, value, IS_TMP_VAR, 0);

}
/* }}} */
Expand Down
34 changes: 34 additions & 0 deletions ext/reflection/tests/gh24729.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--TEST--
GH-24729 (Use-after-free in ReflectionClass::setStaticPropertyValue() when the old value's destructor unbinds the property)
--FILE--
<?php
class A { public static $x; }
class Old {
public function __destruct() {
unset($GLOBALS['y']);
$z = 1;
A::$x = &$z;
}
}
$y = new Old;
A::$x = &$y;
(new ReflectionClass('A'))->setStaticPropertyValue('x', str_repeat('A', 64));
var_dump(A::$x);

class B { public static string $x = ''; }
class S {
public function __toString(): string {
unset($GLOBALS['w']);
$z = 'z';
B::$x = &$z;
return str_repeat('B', 8);
}
}
$w = 'old';
B::$x = &$w;
(new ReflectionClass('B'))->setStaticPropertyValue('x', new S);
var_dump(B::$x);
?>
--EXPECT--
int(1)
string(8) "BBBBBBBB"
Loading