Don't leak internal flags in reflection

If someone complains, we may re-expose specific flags while also
adding corresponding class constants for them.
This commit is contained in:
Nikita Popov 2017-04-22 16:44:20 +02:00
parent 0710eee043
commit d5c6fcc3ba
5 changed files with 52 additions and 47 deletions

View File

@ -3460,13 +3460,15 @@ ZEND_METHOD(reflection_method, getModifiers)
{
reflection_object *intern;
zend_function *mptr;
uint32_t keep_flags = ZEND_ACC_PPP_MASK | ZEND_ACC_IMPLICIT_PUBLIC
| ZEND_ACC_STATIC | ZEND_ACC_ABSTRACT | ZEND_ACC_FINAL;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
GET_REFLECTION_OBJECT_PTR(mptr);
RETURN_LONG(mptr->common.fn_flags);
RETURN_LONG((mptr->common.fn_flags & keep_flags));
}
/* }}} */
@ -4663,13 +4665,15 @@ ZEND_METHOD(reflection_class, getModifiers)
{
reflection_object *intern;
zend_class_entry *ce;
uint32_t keep_flags = ZEND_ACC_FINAL
| ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
GET_REFLECTION_OBJECT_PTR(ce);
RETURN_LONG(ce->ce_flags & ~(ZEND_ACC_CONSTANTS_UPDATED|ZEND_ACC_USE_GUARDS|ZEND_ACC_INHERITED));
RETURN_LONG((ce->ce_flags & keep_flags));
}
/* }}} */
@ -5451,13 +5455,14 @@ ZEND_METHOD(reflection_property, getModifiers)
{
reflection_object *intern;
property_reference *ref;
uint32_t keep_flags = ZEND_ACC_PPP_MASK | ZEND_ACC_IMPLICIT_PUBLIC | ZEND_ACC_STATIC;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
GET_REFLECTION_OBJECT_PTR(ref);
RETURN_LONG(ref->prop.flags);
RETURN_LONG((ref->prop.flags & keep_flags));
}
/* }}} */

View File

@ -31,7 +31,7 @@ dump_modifiers('g');
int(0)
int(32)
int(4)
int(64)
int(524288)
int(524352)
int(0)
int(0)
int(0)
int(0)

View File

@ -41,4 +41,4 @@ int(4)
bool(false)
bool(true)
bool(false)
int(64)
int(0)

View File

@ -87,156 +87,156 @@ printf("0x%08x\n", $a->getModifiers());
?>
--EXPECTF--
Modifiers for method TestClass::foo():
0x08010100
0x00000100
Modifiers for method TestClass::stat():
0x08000101
0x00000101
Modifiers for method TestClass::priv():
0x08010400
0x00000400
Modifiers for method TestClass::prot():
0x08010200
0x00000200
Modifiers for method TestClass::fin():
0x08010104
0x00000104
Modifiers for method TestClass::__destruct():
0x08004100
0x00000100
Modifiers for method TestClass::__call():
0x08000100
0x00000100
Modifiers for method TestClass::__clone():
0x08000100
0x00000100
Modifiers for method TestClass::__get():
0x08000100
0x00000100
Modifiers for method TestClass::__set():
0x08000100
0x00000100
Modifiers for method TestClass::__unset():
0x08000100
0x00000100
Modifiers for method TestClass::__isset():
0x08000100
0x00000100
Modifiers for method TestClass::__tostring():
0x08000100
0x00000100
Modifiers for method TestClass::__sleep():
0x08010100
0x00000100
Modifiers for method TestClass::__wakeup():
0x08010100
0x00000100
Modifiers for method TestClass::__set_state():
0x08010100
0x00000100
Modifiers for method TestClass::__autoload():
0x08010100
0x00000100
Modifiers for method TestClass::foo():
0x08010100
0x00000100
Modifiers for method TestClass::stat():
0x08000101
0x00000101
Modifiers for method TestClass::priv():
0x08010400
0x00000400
Modifiers for method TestClass::prot():
0x08010200
0x00000200
Modifiers for method TestClass::fin():
0x08010104
0x00000104
Modifiers for method TestClass::__destruct():
0x08004100
0x00000100
Modifiers for method TestClass::__call():
0x08000100
0x00000100
Modifiers for method TestClass::__clone():
0x08000100
0x00000100
Modifiers for method TestClass::__get():
0x08000100
0x00000100
Modifiers for method TestClass::__set():
0x08000100
0x00000100
Modifiers for method TestClass::__unset():
0x08000100
0x00000100
Modifiers for method TestClass::__isset():
0x08000100
0x00000100
Modifiers for method TestClass::__tostring():
0x08000100
0x00000100
Modifiers for method TestClass::__sleep():
0x08010100
0x00000100
Modifiers for method TestClass::__wakeup():
0x08010100
0x00000100
Modifiers for method TestClass::__set_state():
0x08010100
0x00000100
Modifiers for method TestClass::__autoload():
0x08010100
0x00000100
Modifiers for method TestInterface::int():
0x08000102
0x00000102
Modifiers for method TestInterface::__clone():
0x08000102
0x00000102
Modifiers for method AbstractClass::foo():
0x08010102
0x00000102
Wrong number of params:
Warning: ReflectionMethod::getModifiers() expects exactly 0 parameters, 1 given in %sReflectionMethod_getModifiers_basic.php on line %d
Warning: ReflectionMethod::getModifiers() expects exactly 0 parameters, 1 given in %s on line %d
ReflectionMethod::getModifiers() modifiers:
0x00000100

View File

@ -37,10 +37,10 @@ D::a1: int(256)
C::a2: int(512)
D::a2: int(512)
C::a3: int(1024)
D::a3: int(3072)
D::a3: int(1024)
C::a4: int(257)
D::a4: int(257)
C::a5: int(513)
D::a5: int(513)
C::a6: int(1025)
D::a6: int(3073)
D::a6: int(1025)