-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Fix GH-13970: Incorrect validation of #[\Attribute]’s first parameter #13976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3755,6 +3755,19 @@ static zend_result preload_resolve_deps(preload_error *error, const zend_class_e | |
return SUCCESS; | ||
} | ||
|
||
static zend_result preload_update_constant(zval *val, zend_class_entry *scope) | ||
{ | ||
zval tmp; | ||
ZVAL_COPY(&tmp, val); | ||
if (zval_update_constant_ex(&tmp, scope) == FAILURE || Z_COLLECTABLE(tmp)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see why all There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Too conservative maybe yes, an alternative is looping (recursively) over the array and checking if they contain objects. |
||
zval_ptr_dtor(&tmp); | ||
return FAILURE; | ||
} | ||
zval_ptr_dtor_nogc(val); | ||
ZVAL_COPY_VALUE(val, &tmp); | ||
return SUCCESS; | ||
} | ||
|
||
static bool preload_try_resolve_constants(zend_class_entry *ce) | ||
{ | ||
bool ok, changed, was_changed = false; | ||
|
@@ -3768,7 +3781,7 @@ static bool preload_try_resolve_constants(zend_class_entry *ce) | |
ZEND_HASH_MAP_FOREACH_PTR(&ce->constants_table, c) { | ||
val = &c->value; | ||
if (Z_TYPE_P(val) == IS_CONSTANT_AST) { | ||
if (EXPECTED(zval_update_constant_ex(val, c->ce) == SUCCESS)) { | ||
if (EXPECTED(preload_update_constant(val, c->ce) == SUCCESS)) { | ||
was_changed = changed = true; | ||
} else { | ||
ok = false; | ||
|
@@ -3786,7 +3799,7 @@ static bool preload_try_resolve_constants(zend_class_entry *ce) | |
val = &ce->default_properties_table[i]; | ||
if (Z_TYPE_P(val) == IS_CONSTANT_AST) { | ||
zend_property_info *prop = ce->properties_info_table[i]; | ||
if (UNEXPECTED(zval_update_constant_ex(val, prop->ce) != SUCCESS)) { | ||
if (UNEXPECTED(preload_update_constant(val, prop->ce) != SUCCESS)) { | ||
resolved = ok = false; | ||
} | ||
} | ||
|
@@ -3802,7 +3815,7 @@ static bool preload_try_resolve_constants(zend_class_entry *ce) | |
val = ce->default_static_members_table + ce->default_static_members_count - 1; | ||
while (count) { | ||
if (Z_TYPE_P(val) == IS_CONSTANT_AST) { | ||
if (UNEXPECTED(zval_update_constant_ex(val, ce) != SUCCESS)) { | ||
if (UNEXPECTED(preload_update_constant(val, ce) != SUCCESS)) { | ||
resolved = ok = false; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--TEST-- | ||
GH-13970 (Incorrect validation of #[\Attribute]’s first parameter) | ||
--EXTENSIONS-- | ||
zend_test | ||
--FILE-- | ||
<?php | ||
#[Attribute(\ZendTestUnitEnum::Foo)] | ||
class Foo { | ||
|
||
} | ||
|
||
#[Foo] | ||
function test1() { | ||
|
||
} | ||
|
||
$reflection = new ReflectionFunction('test1'); | ||
var_dump($reflection->getAttributes()[0]->newInstance()); | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Attribute::__construct(): Argument #1 ($flags) must be of type int, ZendTestUnitEnum given in %s on line %d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May this should be replaced by
if (CG(compiler_options) & ZEND_COMPILE_PRELOAD) {
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replacing this with
CG(in_compilation) && (CG(compiler_options) & ZEND_COMPILE_PRELOAD)
fixes the issue when not in preloading, but the issue still remains when in preloading.