Skip to content

Commit

Permalink
Merge branch 'PHP-8.3'
Browse files Browse the repository at this point in the history
* PHP-8.3:
  Fix leak of call->extra_named_params on internal __call
  • Loading branch information
iluuu1994 committed Dec 1, 2023
2 parents 2d8f7df + b7a468c commit 30acbba
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -8887,6 +8887,9 @@ ZEND_VM_HANDLER(158, ZEND_CALL_TRAMPOLINE, ANY, ANY, SPEC(OBSERVER))
EG(current_execute_data) = call->prev_execute_data;

zend_vm_stack_free_args(call);
if (UNEXPECTED(call_info & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS)) {
zend_free_extra_named_params(call->extra_named_params);
}
if (ret == &retval) {
zval_ptr_dtor(ret);
}
Expand Down
6 changes: 6 additions & 0 deletions Zend/zend_vm_execute.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions ext/zend_test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ static zend_class_entry *zend_test_ns2_ns_foo_class;
static zend_class_entry *zend_test_unit_enum;
static zend_class_entry *zend_test_string_enum;
static zend_class_entry *zend_test_int_enum;
static zend_class_entry *zend_test_magic_call;
static zend_object_handlers zend_test_class_handlers;

static int le_throwing_resource;
Expand Down Expand Up @@ -962,6 +963,24 @@ static ZEND_METHOD(ZendTestForbidDynamicCall, callStatic)
zend_forbid_dynamic_call();
}

static ZEND_METHOD(_ZendTestMagicCall, __call)
{
zend_string *name;
zval *arguments;

ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_STR(name)
Z_PARAM_ARRAY(arguments)
ZEND_PARSE_PARAMETERS_END();

zval name_zv;
ZVAL_STR(&name_zv, name);

zend_string_addref(name);
Z_TRY_ADDREF_P(arguments);
RETURN_ARR(zend_new_pair(&name_zv, arguments));
}

PHP_INI_BEGIN()
STD_PHP_INI_BOOLEAN("zend_test.replace_zend_execute_ex", "0", PHP_INI_SYSTEM, OnUpdateBool, replace_zend_execute_ex, zend_zend_test_globals, zend_test_globals)
STD_PHP_INI_BOOLEAN("zend_test.register_passes", "0", PHP_INI_SYSTEM, OnUpdateBool, register_passes, zend_zend_test_globals, zend_test_globals)
Expand Down Expand Up @@ -1146,6 +1165,8 @@ PHP_MINIT_FUNCTION(zend_test)
zend_test_string_enum = register_class_ZendTestStringEnum();
zend_test_int_enum = register_class_ZendTestIntEnum();

zend_test_magic_call = register_class__ZendTestMagicCall();

zend_register_functions(NULL, ext_function_legacy, NULL, EG(current_module)->type);

// Loading via dl() not supported with the observer API
Expand Down
5 changes: 5 additions & 0 deletions ext/zend_test/test.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ static public function variadicTest(string|Iterator ...$elements) : static {}
public function takesUnionType(stdclass|Iterator $arg): void {}
}

class _ZendTestMagicCall
{
public function __call(string $name, array $args): mixed {}
}

class _ZendTestChildClass extends _ZendTestClass
{
public function returnsThrowable(): Exception {}
Expand Down
24 changes: 23 additions & 1 deletion ext/zend_test/test_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions ext/zend_test/tests/internal_magic_call.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
GH-12835: call->extra_named_params leaks on internal __call
--EXTENSIONS--
zend_test
--FILE--
<?php
$obj = new _ZendTestMagicCall;
var_dump($obj->test('a', 'b', c: 'c'));
?>
--EXPECT--
array(2) {
[0]=>
string(4) "test"
[1]=>
array(3) {
[0]=>
string(1) "a"
[1]=>
string(1) "b"
["c"]=>
string(1) "c"
}
}

0 comments on commit 30acbba

Please sign in to comment.