Skip to content

Commit 820ac06

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fix #62474: com_event_sink crashes on certain arguments
2 parents f4b0b32 + 2da00fa commit 820ac06

File tree

2 files changed

+38
-20
lines changed

2 files changed

+38
-20
lines changed

ext/com_dotnet/com_typeinfo.c

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -306,18 +306,20 @@ ITypeInfo *php_com_locate_typeinfo(char *typelibname, php_com_dotnet_object *obj
306306

307307
if (obj) {
308308
if (dispname == NULL && sink) {
309-
IProvideClassInfo2 *pci2;
310-
IProvideClassInfo *pci;
309+
if (V_VT(&obj->v) == VT_DISPATCH) {
310+
IProvideClassInfo2 *pci2;
311+
IProvideClassInfo *pci;
311312

312-
if (SUCCEEDED(IDispatch_QueryInterface(V_DISPATCH(&obj->v), &IID_IProvideClassInfo2, (void**)&pci2))) {
313-
gotguid = SUCCEEDED(IProvideClassInfo2_GetGUID(pci2, GUIDKIND_DEFAULT_SOURCE_DISP_IID, &iid));
314-
IProvideClassInfo2_Release(pci2);
315-
}
316-
if (!gotguid && SUCCEEDED(IDispatch_QueryInterface(V_DISPATCH(&obj->v), &IID_IProvideClassInfo, (void**)&pci))) {
317-
/* examine the available interfaces */
318-
/* TODO: write some code here */
319-
php_error_docref(NULL, E_WARNING, "IProvideClassInfo: this code not yet written!");
320-
IProvideClassInfo_Release(pci);
313+
if (SUCCEEDED(IDispatch_QueryInterface(V_DISPATCH(&obj->v), &IID_IProvideClassInfo2, (void**)&pci2))) {
314+
gotguid = SUCCEEDED(IProvideClassInfo2_GetGUID(pci2, GUIDKIND_DEFAULT_SOURCE_DISP_IID, &iid));
315+
IProvideClassInfo2_Release(pci2);
316+
}
317+
if (!gotguid && SUCCEEDED(IDispatch_QueryInterface(V_DISPATCH(&obj->v), &IID_IProvideClassInfo, (void**)&pci))) {
318+
/* examine the available interfaces */
319+
/* TODO: write some code here */
320+
php_error_docref(NULL, E_WARNING, "IProvideClassInfo: this code not yet written!");
321+
IProvideClassInfo_Release(pci);
322+
}
321323
}
322324
} else if (dispname == NULL) {
323325
if (obj->typeinfo) {
@@ -334,15 +336,17 @@ ITypeInfo *php_com_locate_typeinfo(char *typelibname, php_com_dotnet_object *obj
334336
/* get the library from the object; the rest will be dealt with later */
335337
ITypeInfo_GetContainingTypeLib(obj->typeinfo, &typelib, &idx);
336338
} else if (typelibname == NULL) {
337-
IDispatch_GetTypeInfo(V_DISPATCH(&obj->v), 0, LANG_NEUTRAL, &typeinfo);
338-
if (dispname) {
339-
unsigned int idx;
340-
/* get the library from the object; the rest will be dealt with later */
341-
ITypeInfo_GetContainingTypeLib(typeinfo, &typelib, &idx);
342-
343-
if (typelib) {
344-
ITypeInfo_Release(typeinfo);
345-
typeinfo = NULL;
339+
if (V_VT(&obj->v) == VT_DISPATCH) {
340+
IDispatch_GetTypeInfo(V_DISPATCH(&obj->v), 0, LANG_NEUTRAL, &typeinfo);
341+
if (dispname) {
342+
unsigned int idx;
343+
/* get the library from the object; the rest will be dealt with later */
344+
ITypeInfo_GetContainingTypeLib(typeinfo, &typelib, &idx);
345+
346+
if (typelib) {
347+
ITypeInfo_Release(typeinfo);
348+
typeinfo = NULL;
349+
}
346350
}
347351
}
348352
}

ext/com_dotnet/tests/bug62474.phpt

Lines changed: 14 additions & 0 deletions
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)