Skip to content

Commit 64d511e

Browse files
committed
Fix GH-18641: Accessing a BcMath\Number property by ref crashes
The properties are virtual so we need a custom get_property_ptr_ptr handler. Closes GH-18637.
1 parent 7efe96d commit 64d511e

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.4.9
44

5+
- BcMath:
6+
. Fixed bug GH-18641 (Accessing a BcMath\Number property by ref crashes).
7+
(nielsdos)
8+
59
- Intl:
610
. Fix memory leak in intl_datetime_decompose() on failure. (nielsdos)
711

ext/bcmath/bcmath.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,12 @@ static zval *bcmath_number_read_property(zend_object *obj, zend_string *name, in
971971
return zend_std_read_property(obj, name, type, cache_slot, rv);
972972
}
973973

974+
static zval *bcmath_number_get_property_ptr_ptr(zend_object *object, zend_string *member, int type, void **cache_slot)
975+
{
976+
/* Must always go through read property because all properties are virtual, and no dynamic properties are allowed. */
977+
return NULL;
978+
}
979+
974980
static int bcmath_number_has_property(zend_object *obj, zend_string *name, int check_empty, void **cache_slot)
975981
{
976982
if (check_empty == ZEND_PROPERTY_NOT_EMPTY) {
@@ -1014,6 +1020,7 @@ static void bcmath_number_register_class(void)
10141020
bcmath_number_obj_handlers.unset_property = bcmath_number_unset_property;
10151021
bcmath_number_obj_handlers.has_property = bcmath_number_has_property;
10161022
bcmath_number_obj_handlers.read_property = bcmath_number_read_property;
1023+
bcmath_number_obj_handlers.get_property_ptr_ptr = bcmath_number_get_property_ptr_ptr;
10171024
bcmath_number_obj_handlers.get_properties_for = bcmath_number_get_properties_for;
10181025
bcmath_number_obj_handlers.cast_object = bcmath_number_cast_object;
10191026
}

ext/bcmath/tests/number/gh18641.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
GH-18641 (Accessing a BcMath\Number property by ref crashes)
3+
--EXTENSIONS--
4+
bcmath
5+
--FILE--
6+
<?php
7+
$a = new BCMath\Number("1");
8+
$fusion = $a;
9+
$x = &$fusion->value;
10+
var_dump($x);
11+
?>
12+
--EXPECT--
13+
string(1) "1"

0 commit comments

Comments
 (0)