From 4b9d3909b841c1ca919e25a37838c1cd9b3445f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bernon?= Date: Wed, 30 Sep 2020 12:37:39 +0200 Subject: [PATCH] wbemprox: Set variant type to VT_NULL if BSTR is NULL. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mafia III launcher crashes when querying video controllers when it passes the NULL __PATH value through COM marshalling. Signed-off-by: RĂ©mi Bernon Signed-off-by: Hans Leidekker Signed-off-by: Alexandre Julliard --- dlls/wbemprox/query.c | 12 ++++++++---- dlls/wbemprox/tests/query.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/dlls/wbemprox/query.c b/dlls/wbemprox/query.c index 6ac5ad5b770..525381d88d2 100644 --- a/dlls/wbemprox/query.c +++ b/dlls/wbemprox/query.c @@ -946,22 +946,24 @@ static HRESULT get_system_propval( const struct view *view, UINT table_index, UI if (type) *type = CIM_SINT32; return S_OK; } - else if (!wcsicmp( name, L"__NAMESPACE" )) + if (!wcsicmp( name, L"__NAMESPACE" )) { if (ret) { V_VT( ret ) = VT_BSTR; V_BSTR( ret ) = view->proplist ? NULL : build_namespace(); + if (!V_BSTR( ret )) V_VT( ret ) = VT_NULL; } if (type) *type = CIM_STRING; return S_OK; } - else if (!wcsicmp( name, L"__PATH" )) + if (!wcsicmp( name, L"__PATH" )) { if (ret) { V_VT( ret ) = VT_BSTR; V_BSTR( ret ) = build_path( view, table_index, result_index, name ); + if (!V_BSTR( ret )) V_VT( ret ) = VT_NULL; } if (type) *type = CIM_STRING; return S_OK; @@ -976,22 +978,24 @@ static HRESULT get_system_propval( const struct view *view, UINT table_index, UI if (type) *type = CIM_SINT32; return S_OK; } - else if (!wcsicmp( name, L"__RELPATH" )) + if (!wcsicmp( name, L"__RELPATH" )) { if (ret) { V_VT( ret ) = VT_BSTR; V_BSTR( ret ) = build_relpath( view, table_index, result_index, name ); + if (!V_BSTR( ret )) V_VT( ret ) = VT_NULL; } if (type) *type = CIM_STRING; return S_OK; } - else if (!wcsicmp( name, L"__SERVER" )) + if (!wcsicmp( name, L"__SERVER" )) { if (ret) { V_VT( ret ) = VT_BSTR; V_BSTR( ret ) = view->proplist ? NULL : build_servername(); + if (!V_BSTR( ret )) V_VT( ret ) = VT_NULL; } if (type) *type = CIM_STRING; return S_OK; diff --git a/dlls/wbemprox/tests/query.c b/dlls/wbemprox/tests/query.c index 74fdfaa9bc8..d1ce42d64cb 100644 --- a/dlls/wbemprox/tests/query.c +++ b/dlls/wbemprox/tests/query.c @@ -1414,6 +1414,13 @@ static void test_Win32_VideoController( IWbemServices *services ) hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count ); if (hr != S_OK) break; + check_property( obj, L"__CLASS", VT_BSTR, CIM_STRING ); + check_property( obj, L"__GENUS", VT_I4, CIM_SINT32 ); + check_property( obj, L"__NAMESPACE", VT_BSTR, CIM_STRING ); + check_property( obj, L"__PATH", VT_BSTR, CIM_STRING ); + check_property( obj, L"__PROPERTY_COUNT", VT_I4, CIM_SINT32 ); + check_property( obj, L"__RELPATH", VT_BSTR, CIM_STRING ); + check_property( obj, L"__SERVER", VT_BSTR, CIM_STRING ); check_property( obj, L"AdapterCompatibility", VT_BSTR, CIM_STRING ); check_property( obj, L"Availability", VT_I4, CIM_UINT16 ); check_property( obj, L"ConfigManagerErrorCode", VT_I4, CIM_UINT32 ); @@ -1432,6 +1439,31 @@ static void test_Win32_VideoController( IWbemServices *services ) IWbemClassObject_Release( obj ); } + IEnumWbemClassObject_Release( result ); + SysFreeString( query ); + + query = SysAllocString( L"SELECT AdapterRAM FROM Win32_VideoController" ); + hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result ); + if (hr != S_OK) + { + win_skip( "Win32_VideoController not available\n" ); + return; + } + + for (;;) + { + hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count ); + if (hr != S_OK) break; + check_property( obj, L"__CLASS", VT_BSTR, CIM_STRING ); + check_property( obj, L"__GENUS", VT_I4, CIM_SINT32 ); + check_property( obj, L"__NAMESPACE", VT_NULL, CIM_STRING ); + check_property( obj, L"__PATH", VT_NULL, CIM_STRING ); + check_property( obj, L"__PROPERTY_COUNT", VT_I4, CIM_SINT32 ); + check_property( obj, L"__RELPATH", VT_NULL, CIM_STRING ); + check_property( obj, L"__SERVER", VT_NULL, CIM_STRING ); + IWbemClassObject_Release( obj ); + } + IEnumWbemClassObject_Release( result ); SysFreeString( query ); SysFreeString( wql );