]> granicus.if.org Git - php/commitdiff
Don't leak internal flags in reflection
authorNikita Popov <nikita.ppv@gmail.com>
Sat, 22 Apr 2017 14:44:20 +0000 (16:44 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Sat, 22 Apr 2017 14:44:20 +0000 (16:44 +0200)
If someone complains, we may re-expose specific flags while also
adding corresponding class constants for them.

ext/reflection/php_reflection.c
ext/reflection/tests/ReflectionClass_getModifiers_basic.phpt
ext/reflection/tests/ReflectionClass_modifiers_001.phpt
ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt
ext/reflection/tests/ReflectionProperty_getModifiers_basic.phpt

index b9ae4d1c85c4d737d96ab692a04a8dceaa6c7849..b8c984a8bfc38776dd7429b59421497a9400b316 100644 (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));
 }
 /* }}} */
 
index 68189db2bbb5c5bd8ce26ab9701ce7136c5fbf30..f77bbacda7c29653e9dd13909998edfae382a90c 100644 (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)
index 7f62b565a23ca580deff3731fb978125a0d131d2..a1464a5ab99665c78c7b1dc5423873f53276e1ec 100644 (file)
@@ -41,4 +41,4 @@ int(4)
 bool(false)
 bool(true)
 bool(false)
-int(64)
\ No newline at end of file
+int(0)
index 34207550647a7db0c572a2366ec8951ae4d91c0a..55aea10763aa11f62f929fdf99639226a6cb384a 100644 (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
index 0d1b6bd13a2b361051ad40debbc003c8d05eddfe..38137551fceba6d20b5c551ca7ec974d11c17ba0 100644 (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)