summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2017-04-22 16:44:20 +0200
committerNikita Popov <nikita.ppv@gmail.com>2017-04-22 16:44:20 +0200
commitd5c6fcc3ba275c79da85537f9792e4eb3c6a0c39 (patch)
tree05e6d78205891aa5982beffa4a6b490a7450bbd5
parent0710eee043721cc0a6c36e40cbc19b5dc40933e6 (diff)
downloadphp-git-d5c6fcc3ba275c79da85537f9792e4eb3c6a0c39.tar.gz
Don't leak internal flags in reflection
If someone complains, we may re-expose specific flags while also adding corresponding class constants for them.
-rw-r--r--ext/reflection/php_reflection.c11
-rw-r--r--ext/reflection/tests/ReflectionClass_getModifiers_basic.phpt6
-rw-r--r--ext/reflection/tests/ReflectionClass_modifiers_001.phpt2
-rw-r--r--ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt76
-rw-r--r--ext/reflection/tests/ReflectionProperty_getModifiers_basic.phpt4
5 files changed, 52 insertions, 47 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index b9ae4d1c85..b8c984a8bf 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -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));
}
/* }}} */
diff --git a/ext/reflection/tests/ReflectionClass_getModifiers_basic.phpt b/ext/reflection/tests/ReflectionClass_getModifiers_basic.phpt
index 68189db2bb..f77bbacda7 100644
--- a/ext/reflection/tests/ReflectionClass_getModifiers_basic.phpt
+++ b/ext/reflection/tests/ReflectionClass_getModifiers_basic.phpt
@@ -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)
diff --git a/ext/reflection/tests/ReflectionClass_modifiers_001.phpt b/ext/reflection/tests/ReflectionClass_modifiers_001.phpt
index 7f62b565a2..a1464a5ab9 100644
--- a/ext/reflection/tests/ReflectionClass_modifiers_001.phpt
+++ b/ext/reflection/tests/ReflectionClass_modifiers_001.phpt
@@ -41,4 +41,4 @@ int(4)
bool(false)
bool(true)
bool(false)
-int(64) \ No newline at end of file
+int(0)
diff --git a/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt b/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt
index 3420755064..55aea10763 100644
--- a/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt
+++ b/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt
@@ -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
diff --git a/ext/reflection/tests/ReflectionProperty_getModifiers_basic.phpt b/ext/reflection/tests/ReflectionProperty_getModifiers_basic.phpt
index 0d1b6bd13a..38137551fc 100644
--- a/ext/reflection/tests/ReflectionProperty_getModifiers_basic.phpt
+++ b/ext/reflection/tests/ReflectionProperty_getModifiers_basic.phpt
@@ -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)