Skip to content

Commit 8fa745e

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.
1 parent 7efe96d commit 8fa745e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

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
}
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)