Skip to content

Commit d5c6fcc

Browse files
committed
Don't leak internal flags in reflection
If someone complains, we may re-expose specific flags while also adding corresponding class constants for them.
1 parent 0710eee commit d5c6fcc

5 files changed

+52
-47
lines changed

ext/reflection/php_reflection.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -3460,13 +3460,15 @@ ZEND_METHOD(reflection_method, getModifiers)
34603460
{
34613461
reflection_object *intern;
34623462
zend_function *mptr;
3463+
uint32_t keep_flags = ZEND_ACC_PPP_MASK | ZEND_ACC_IMPLICIT_PUBLIC
3464+
| ZEND_ACC_STATIC | ZEND_ACC_ABSTRACT | ZEND_ACC_FINAL;
34633465

34643466
if (zend_parse_parameters_none() == FAILURE) {
34653467
return;
34663468
}
34673469
GET_REFLECTION_OBJECT_PTR(mptr);
34683470

3469-
RETURN_LONG(mptr->common.fn_flags);
3471+
RETURN_LONG((mptr->common.fn_flags & keep_flags));
34703472
}
34713473
/* }}} */
34723474

@@ -4663,13 +4665,15 @@ ZEND_METHOD(reflection_class, getModifiers)
46634665
{
46644666
reflection_object *intern;
46654667
zend_class_entry *ce;
4668+
uint32_t keep_flags = ZEND_ACC_FINAL
4669+
| ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS;
46664670

46674671
if (zend_parse_parameters_none() == FAILURE) {
46684672
return;
46694673
}
46704674
GET_REFLECTION_OBJECT_PTR(ce);
46714675

4672-
RETURN_LONG(ce->ce_flags & ~(ZEND_ACC_CONSTANTS_UPDATED|ZEND_ACC_USE_GUARDS|ZEND_ACC_INHERITED));
4676+
RETURN_LONG((ce->ce_flags & keep_flags));
46734677
}
46744678
/* }}} */
46754679

@@ -5451,13 +5455,14 @@ ZEND_METHOD(reflection_property, getModifiers)
54515455
{
54525456
reflection_object *intern;
54535457
property_reference *ref;
5458+
uint32_t keep_flags = ZEND_ACC_PPP_MASK | ZEND_ACC_IMPLICIT_PUBLIC | ZEND_ACC_STATIC;
54545459

54555460
if (zend_parse_parameters_none() == FAILURE) {
54565461
return;
54575462
}
54585463
GET_REFLECTION_OBJECT_PTR(ref);
54595464

5460-
RETURN_LONG(ref->prop.flags);
5465+
RETURN_LONG((ref->prop.flags & keep_flags));
54615466
}
54625467
/* }}} */
54635468

ext/reflection/tests/ReflectionClass_getModifiers_basic.phpt

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ dump_modifiers('g');
3131
int(0)
3232
int(32)
3333
int(4)
34-
int(64)
35-
int(524288)
36-
int(524352)
34+
int(0)
35+
int(0)
36+
int(0)
3737
int(0)

ext/reflection/tests/ReflectionClass_modifiers_001.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ int(4)
4141
bool(false)
4242
bool(true)
4343
bool(false)
44-
int(64)
44+
int(0)

ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt

+38-38
Original file line numberDiff line numberDiff line change
@@ -87,156 +87,156 @@ printf("0x%08x\n", $a->getModifiers());
8787
?>
8888
--EXPECTF--
8989
Modifiers for method TestClass::foo():
90-
0x08010100
90+
0x00000100
9191

9292

9393
Modifiers for method TestClass::stat():
94-
0x08000101
94+
0x00000101
9595

9696

9797
Modifiers for method TestClass::priv():
98-
0x08010400
98+
0x00000400
9999

100100

101101
Modifiers for method TestClass::prot():
102-
0x08010200
102+
0x00000200
103103

104104

105105
Modifiers for method TestClass::fin():
106-
0x08010104
106+
0x00000104
107107

108108

109109
Modifiers for method TestClass::__destruct():
110-
0x08004100
110+
0x00000100
111111

112112

113113
Modifiers for method TestClass::__call():
114-
0x08000100
114+
0x00000100
115115

116116

117117
Modifiers for method TestClass::__clone():
118-
0x08000100
118+
0x00000100
119119

120120

121121
Modifiers for method TestClass::__get():
122-
0x08000100
122+
0x00000100
123123

124124

125125
Modifiers for method TestClass::__set():
126-
0x08000100
126+
0x00000100
127127

128128

129129
Modifiers for method TestClass::__unset():
130-
0x08000100
130+
0x00000100
131131

132132

133133
Modifiers for method TestClass::__isset():
134-
0x08000100
134+
0x00000100
135135

136136

137137
Modifiers for method TestClass::__tostring():
138-
0x08000100
138+
0x00000100
139139

140140

141141
Modifiers for method TestClass::__sleep():
142-
0x08010100
142+
0x00000100
143143

144144

145145
Modifiers for method TestClass::__wakeup():
146-
0x08010100
146+
0x00000100
147147

148148

149149
Modifiers for method TestClass::__set_state():
150-
0x08010100
150+
0x00000100
151151

152152

153153
Modifiers for method TestClass::__autoload():
154-
0x08010100
154+
0x00000100
155155

156156

157157
Modifiers for method TestClass::foo():
158-
0x08010100
158+
0x00000100
159159

160160

161161
Modifiers for method TestClass::stat():
162-
0x08000101
162+
0x00000101
163163

164164

165165
Modifiers for method TestClass::priv():
166-
0x08010400
166+
0x00000400
167167

168168

169169
Modifiers for method TestClass::prot():
170-
0x08010200
170+
0x00000200
171171

172172

173173
Modifiers for method TestClass::fin():
174-
0x08010104
174+
0x00000104
175175

176176

177177
Modifiers for method TestClass::__destruct():
178-
0x08004100
178+
0x00000100
179179

180180

181181
Modifiers for method TestClass::__call():
182-
0x08000100
182+
0x00000100
183183

184184

185185
Modifiers for method TestClass::__clone():
186-
0x08000100
186+
0x00000100
187187

188188

189189
Modifiers for method TestClass::__get():
190-
0x08000100
190+
0x00000100
191191

192192

193193
Modifiers for method TestClass::__set():
194-
0x08000100
194+
0x00000100
195195

196196

197197
Modifiers for method TestClass::__unset():
198-
0x08000100
198+
0x00000100
199199

200200

201201
Modifiers for method TestClass::__isset():
202-
0x08000100
202+
0x00000100
203203

204204

205205
Modifiers for method TestClass::__tostring():
206-
0x08000100
206+
0x00000100
207207

208208

209209
Modifiers for method TestClass::__sleep():
210-
0x08010100
210+
0x00000100
211211

212212

213213
Modifiers for method TestClass::__wakeup():
214-
0x08010100
214+
0x00000100
215215

216216

217217
Modifiers for method TestClass::__set_state():
218-
0x08010100
218+
0x00000100
219219

220220

221221
Modifiers for method TestClass::__autoload():
222-
0x08010100
222+
0x00000100
223223

224224

225225
Modifiers for method TestInterface::int():
226-
0x08000102
226+
0x00000102
227227

228228

229229
Modifiers for method TestInterface::__clone():
230-
0x08000102
230+
0x00000102
231231

232232

233233
Modifiers for method AbstractClass::foo():
234-
0x08010102
234+
0x00000102
235235

236236

237237
Wrong number of params:
238238

239-
Warning: ReflectionMethod::getModifiers() expects exactly 0 parameters, 1 given in %sReflectionMethod_getModifiers_basic.php on line %d
239+
Warning: ReflectionMethod::getModifiers() expects exactly 0 parameters, 1 given in %s on line %d
240240

241241
ReflectionMethod::getModifiers() modifiers:
242242
0x00000100

ext/reflection/tests/ReflectionProperty_getModifiers_basic.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ D::a1: int(256)
3737
C::a2: int(512)
3838
D::a2: int(512)
3939
C::a3: int(1024)
40-
D::a3: int(3072)
40+
D::a3: int(1024)
4141
C::a4: int(257)
4242
D::a4: int(257)
4343
C::a5: int(513)
4444
D::a5: int(513)
4545
C::a6: int(1025)
46-
D::a6: int(3073)
46+
D::a6: int(1025)

0 commit comments

Comments
 (0)