Skip to content

Commit 7424bfc

Browse files
committed
Fix #62474: com_event_sink crashes on certain arguments
We have to make sure that the variant is of type `VT_DISPATCH` before we access it as such. Closes phpGH-6372.
1 parent 848e24f commit 7424bfc

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ PHP NEWS
88
. Fixed bug #80258 (Windows Deduplication Enabled, randon permission errors).
99
(cmb)
1010

11+
- COM:
12+
. Fixed bug #62474 (com_event_sink crashes on certain arguments). (cmb)
13+
1114
- IMAP:
1215
. Fixed bug #64076 (imap_sort() does not return FALSE on failure). (cmb)
1316
. Fixed bug #76618 (segfault on imap_reopen). (girgias)

ext/com_dotnet/com_typeinfo.c

+24-20
Original file line numberDiff line numberDiff line change
@@ -267,18 +267,20 @@ ITypeInfo *php_com_locate_typeinfo(char *typelibname, php_com_dotnet_object *obj
267267

268268
if (obj) {
269269
if (dispname == NULL && sink) {
270-
IProvideClassInfo2 *pci2;
271-
IProvideClassInfo *pci;
270+
if (V_VT(&obj->v) == VT_DISPATCH) {
271+
IProvideClassInfo2 *pci2;
272+
IProvideClassInfo *pci;
272273

273-
if (SUCCEEDED(IDispatch_QueryInterface(V_DISPATCH(&obj->v), &IID_IProvideClassInfo2, (void**)&pci2))) {
274-
gotguid = SUCCEEDED(IProvideClassInfo2_GetGUID(pci2, GUIDKIND_DEFAULT_SOURCE_DISP_IID, &iid));
275-
IProvideClassInfo2_Release(pci2);
276-
}
277-
if (!gotguid && SUCCEEDED(IDispatch_QueryInterface(V_DISPATCH(&obj->v), &IID_IProvideClassInfo, (void**)&pci))) {
278-
/* examine the available interfaces */
279-
/* TODO: write some code here */
280-
php_error_docref(NULL, E_WARNING, "IProvideClassInfo: this code not yet written!");
281-
IProvideClassInfo_Release(pci);
274+
if (SUCCEEDED(IDispatch_QueryInterface(V_DISPATCH(&obj->v), &IID_IProvideClassInfo2, (void**)&pci2))) {
275+
gotguid = SUCCEEDED(IProvideClassInfo2_GetGUID(pci2, GUIDKIND_DEFAULT_SOURCE_DISP_IID, &iid));
276+
IProvideClassInfo2_Release(pci2);
277+
}
278+
if (!gotguid && SUCCEEDED(IDispatch_QueryInterface(V_DISPATCH(&obj->v), &IID_IProvideClassInfo, (void**)&pci))) {
279+
/* examine the available interfaces */
280+
/* TODO: write some code here */
281+
php_error_docref(NULL, E_WARNING, "IProvideClassInfo: this code not yet written!");
282+
IProvideClassInfo_Release(pci);
283+
}
282284
}
283285
} else if (dispname == NULL) {
284286
if (obj->typeinfo) {
@@ -295,15 +297,17 @@ ITypeInfo *php_com_locate_typeinfo(char *typelibname, php_com_dotnet_object *obj
295297
/* get the library from the object; the rest will be dealt with later */
296298
ITypeInfo_GetContainingTypeLib(obj->typeinfo, &typelib, &idx);
297299
} else if (typelibname == NULL) {
298-
IDispatch_GetTypeInfo(V_DISPATCH(&obj->v), 0, LANG_NEUTRAL, &typeinfo);
299-
if (dispname) {
300-
unsigned int idx;
301-
/* get the library from the object; the rest will be dealt with later */
302-
ITypeInfo_GetContainingTypeLib(typeinfo, &typelib, &idx);
303-
304-
if (typelib) {
305-
ITypeInfo_Release(typeinfo);
306-
typeinfo = NULL;
300+
if (V_VT(&obj->v) == VT_DISPATCH) {
301+
IDispatch_GetTypeInfo(V_DISPATCH(&obj->v), 0, LANG_NEUTRAL, &typeinfo);
302+
if (dispname) {
303+
unsigned int idx;
304+
/* get the library from the object; the rest will be dealt with later */
305+
ITypeInfo_GetContainingTypeLib(typeinfo, &typelib, &idx);
306+
307+
if (typelib) {
308+
ITypeInfo_Release(typeinfo);
309+
typeinfo = NULL;
310+
}
307311
}
308312
}
309313
}

ext/com_dotnet/tests/bug62474.phpt

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #62474 (com_event_sink crashes on certain arguments)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('com_dotnet')) die('skip com_dotnet extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
var_dump(com_event_sink(new variant, function() {}, array()));
10+
var_dump(com_event_sink(new variant, new variant, 'a'));
11+
?>
12+
--EXPECT--
13+
bool(false)
14+
bool(false)

0 commit comments

Comments
 (0)