Skip to content
Merged
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
47 changes: 8 additions & 39 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1432,13 +1432,7 @@ static void reflection_extension_factory_ex(zval *object, zend_module_entry *mod
static void reflection_extension_factory(zval *object, const char *name_str)
{
size_t name_len = strlen(name_str);
zend_string *lcname;
struct _zend_module_entry *module;

lcname = zend_string_alloc(name_len, 0);
zend_str_tolower_copy(ZSTR_VAL(lcname), name_str, name_len);
module = zend_hash_find_ptr(&module_registry, lcname);
zend_string_efree(lcname);
struct _zend_module_entry *module = zend_hash_str_find_ptr_lc(&module_registry, name_str, name_len);
if (!module) {
return;
}
Expand Down Expand Up @@ -2141,16 +2135,10 @@ ZEND_METHOD(ReflectionFunction, invoke)

zend_call_known_fcc(&fcc, &retval, num_args, params, named_params);

if (Z_TYPE(retval) == IS_UNDEF && !EG(exception)) {
zend_throw_exception_ex(reflection_exception_ptr, 0,
"Invocation of function %s() failed", ZSTR_VAL(fptr->common.function_name));
RETURN_THROWS();
}

if (Z_ISREF(retval)) {
zend_unwrap_reference(&retval);
}
ZVAL_COPY_VALUE(return_value, &retval);
RETURN_COPY_VALUE(&retval);
}
/* }}} */

Expand Down Expand Up @@ -2180,16 +2168,10 @@ ZEND_METHOD(ReflectionFunction, invokeArgs)

zend_call_known_fcc(&fcc, &retval, /* num_params */ 0, /* params */ NULL, params);

if (Z_TYPE(retval) == IS_UNDEF && !EG(exception)) {
zend_throw_exception_ex(reflection_exception_ptr, 0,
"Invocation of function %s() failed", ZSTR_VAL(fptr->common.function_name));
RETURN_THROWS();
}

if (Z_ISREF(retval)) {
zend_unwrap_reference(&retval);
}
ZVAL_COPY_VALUE(return_value, &retval);
RETURN_COPY_VALUE(&retval);
}
/* }}} */

Expand Down Expand Up @@ -3496,16 +3478,10 @@ static void reflection_method_invoke(INTERNAL_FUNCTION_PARAMETERS, int variadic)
callback = _copy_function(mptr);
zend_call_known_function(callback, (object ? Z_OBJ_P(object) : NULL), intern->ce, &retval, argc, params, named_params);

if (Z_TYPE(retval) == IS_UNDEF && !EG(exception)) {
zend_throw_exception_ex(reflection_exception_ptr, 0,
"Invocation of method %s::%s() failed", ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name));
RETURN_THROWS();
}

if (Z_ISREF(retval)) {
zend_unwrap_reference(&retval);
}
ZVAL_COPY_VALUE(return_value, &retval);
RETURN_COPY_VALUE(&retval);
}
/* }}} */

Expand Down Expand Up @@ -6661,28 +6637,21 @@ ZEND_METHOD(ReflectionProperty, isFinal)
ZEND_METHOD(ReflectionExtension, __construct)
{
zval *object;
char *lcname;
reflection_object *intern;
zend_module_entry *module;
char *name_str;
size_t name_len;
ALLOCA_FLAG(use_heap)
zend_string *name_str;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name_str) == FAILURE) {
RETURN_THROWS();
}

object = ZEND_THIS;
intern = Z_REFLECTION_P(object);
lcname = do_alloca(name_len + 1, use_heap);
zend_str_tolower_copy(lcname, name_str, name_len);
if ((module = zend_hash_str_find_ptr(&module_registry, lcname, name_len)) == NULL) {
free_alloca(lcname, use_heap);
if ((module = zend_hash_find_ptr_lc(&module_registry, name_str)) == NULL) {
zend_throw_exception_ex(reflection_exception_ptr, 0,
"Extension \"%s\" does not exist", name_str);
"Extension \"%s\" does not exist", ZSTR_VAL(name_str));
RETURN_THROWS();
}
free_alloca(lcname, use_heap);
zval *prop_name = reflection_prop_name(object);
zval_ptr_dtor(prop_name);
ZVAL_STRING(prop_name, module->name);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
ReflectionFunction::__toString() with bound variables
--FILE--
<?php

$closure_without_bounds = fn () => 0;

$rf = new ReflectionFunction($closure_without_bounds);
echo (string) $rf;

$global = "";
$closure_with_bounds = function() use($global) {
static $counter = 0;
return $counter++;
};

$rf = new ReflectionFunction($closure_with_bounds);
echo (string) $rf;

?>
--EXPECTF--
Closure [ <user> function {closure:%s:%d} ] {
@@ %sReflectionFunction__toString_bound_variables.php 3 - 3
}
Closure [ <user> function {closure:%s:%d} ] {
@@ %sReflectionFunction__toString_bound_variables.php 9 - 12

- Bound Variables [2] {
Variable #0 [ $global ]
Variable #1 [ $counter ]
}
}
4 changes: 2 additions & 2 deletions ext/spl/spl_fixedarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ PHP_METHOD(SplFixedArray, __unserialize)
intern->array.size = 0;
ZEND_HASH_FOREACH_STR_KEY_VAL(data, key, elem) {
if (key == NULL) {
ZVAL_COPY(&intern->array.elements[intern->array.size], elem);
ZVAL_COPY_DEREF(&intern->array.elements[intern->array.size], elem);
intern->array.size++;
} else {
Z_TRY_ADDREF_P(elem);
Expand Down Expand Up @@ -822,7 +822,7 @@ PHP_METHOD(SplFixedArray, offsetGet)
value = spl_fixedarray_object_read_dimension_helper(intern, zindex);

if (value) {
RETURN_COPY_DEREF(value);
RETURN_COPY(value);
} else {
RETURN_NULL();
}
Expand Down
23 changes: 23 additions & 0 deletions ext/spl/tests/gh20614.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
GH-20614 (SplFixedArray incorrectly handles references in deserialization)
--FILE--
<?php

$fa = new SplFixedArray(0);
$nr = 1;
$array = [&$nr];
$fa->__unserialize($array);
var_dump($fa);
unset($fa[0]);
var_dump($fa);

?>
--EXPECT--
object(SplFixedArray)#1 (1) {
[0]=>
int(1)
}
object(SplFixedArray)#1 (1) {
[0]=>
NULL
}