com php-src: Don't leak internal flags in reflection: ext/reflection/php_reflection.c ext/reflection/tests/Refl ectionClass_getModifiers_basic.phpt ext/reflection/test s/ReflectionClass_modifiers_001.phpt ext/reflecti on/tests/ReflectionMethod_getModifiers_basic.phpt ext/r eflection/tests/ReflectionProperty_getModifiers_basic.php t

[email protected] (Nikita Popov)
Newsgroups php.cvs
Message-ID <[email protected]>
Commit:    d5c6fcc3ba275c79da85537f9792e4eb3c6a0c39
Author:    Nikita Popov <[email protected]>         Sat, 22 Apr 2017 16:44:20 +0200
Parents:   0710eee043721cc0a6c36e40cbc19b5dc40933e6
Branches:  master

Link:       http://git.php.net/?p=php-src.git;a=commitdiff;h=d5c6fcc3ba275c79da85537f9792e4eb3c6a0c39

Log:
Don't leak internal flags in reflection

If someone complains, we may re-expose specific flags while also
adding corresponding class constants for them.

Changed paths:
  M  ext/reflection/php_reflection.c
  M  ext/reflection/tests/ReflectionClass_getModifiers_basic.phpt
  M  ext/reflection/tests/ReflectionClass_modifiers_001.phpt
  M  ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt
  M  ext/reflection/tests/ReflectionProperty_getModifiers_basic.phpt


Diff:
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index b9ae4d1..b8c984a 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 68189db..f77bbac 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 7f62b56..a1464a5 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 3420755..55aea10 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 0d1b6bd..3813755 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)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.