diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-10-21 11:55:03 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-10-23 09:46:55 +0200 |
commit | 078df4d144dd7e47a89a697297c04747eb309fa1 (patch) | |
tree | a87a8f0a46ae2f81ebd5ede100e89581327f1a67 /Zend | |
parent | c64dcda5e526d62f5a1b1081963c60e1bd848d68 (diff) | |
download | php-git-078df4d144dd7e47a89a697297c04747eb309fa1.tar.gz |
Don't allow passing unknown named params to class without ctor
See also https://externals.io/message/112083.
Closes GH-6364.
Diffstat (limited to 'Zend')
-rw-r--r-- | Zend/tests/named_params/ctor_extra_named_args.phpt | 23 | ||||
-rw-r--r-- | Zend/zend_execute.c | 8 |
2 files changed, 29 insertions, 2 deletions
diff --git a/Zend/tests/named_params/ctor_extra_named_args.phpt b/Zend/tests/named_params/ctor_extra_named_args.phpt new file mode 100644 index 0000000000..ae569ea65d --- /dev/null +++ b/Zend/tests/named_params/ctor_extra_named_args.phpt @@ -0,0 +1,23 @@ +--TEST-- +Passing unknown named args to a non-existing ctor +--FILE-- +<?php + +class Test {} + +try { + new stdClass(x: "nope"); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} + +try { + new Test(x: "nope"); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +Unknown named parameter $x +Unknown named parameter $x diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index ab231f952f..1cec01591e 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -130,13 +130,12 @@ static ZEND_FUNCTION(pass) } ZEND_BEGIN_ARG_INFO_EX(zend_pass_function_arg_info, 0, 0, 0) - ZEND_ARG_VARIADIC_INFO(0, args) ZEND_END_ARG_INFO() ZEND_API const zend_internal_function zend_pass_function = { ZEND_INTERNAL_FUNCTION, /* type */ {0, 0, 0}, /* arg_flags */ - ZEND_ACC_VARIADIC, /* fn_flags */ + 0, /* fn_flags */ NULL, /* name */ NULL, /* scope */ NULL, /* prototype */ @@ -1097,6 +1096,11 @@ static zend_never_inline ZEND_ATTRIBUTE_UNUSED bool zend_verify_internal_arg_typ * trust that arginfo matches what is enforced by zend_parse_parameters. */ static zend_always_inline zend_bool zend_internal_call_should_throw(zend_function *fbc, zend_execute_data *call) { + if (fbc->internal_function.handler == ZEND_FN(pass)) { + /* Be lenient about the special pass function. */ + return 0; + } + if (fbc->common.required_num_args > ZEND_CALL_NUM_ARGS(call)) { /* Required argument not passed. */ return 1; |