From 56428bd9ad98221ad3631dd1e0d6c80881a88056 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Thu, 4 Jun 2020 16:10:48 +0200 Subject: Properly handle initial object queryInterface return value specifies that this shall return an ANY either of type VOID (so handle that) or of type css.uno.XInterface with non-null value (so throw exceptions for any other kinds of return values). Various Linux Jenkins builds had recently started to sporadically fail during UITest_calc_demo, hitting the assert( type.get()->eTypeClass == typelib_TypeClass_ANY || type.equals(css::uno::TypeDescription(data_.pType))); in the call to binaryurp::BinaryAny::getValue (binaryurp/source/binaryany.cxx), e.g. <. While it is unclear why those failures happen, they highlight that this code did not properly handle all possible (valid or invalid) input. Change-Id: I95db574aa102ff75fa22fd24c697a0cfa24b7aff Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95527 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- binaryurp/source/bridge.cxx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'binaryurp') diff --git a/binaryurp/source/bridge.cxx b/binaryurp/source/bridge.cxx index 1be59b933a70..4d375f414719 100644 --- a/binaryurp/source/bridge.cxx +++ b/binaryurp/source/bridge.cxx @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -873,10 +874,25 @@ css::uno::Reference< css::uno::XInterface > Bridge::getInstance( "com.sun.star.uno.XInterface::queryInterface"), false, inArgs, &ret, &outArgs); throwException(bExc, ret); + auto const t = ret.getType(); + if (t.get()->eTypeClass == typelib_TypeClass_VOID) { + return {}; + } + if (!t.equals(ifc)) { + throw css::uno::RuntimeException( + "initial object queryInterface for OID \"" + sInstanceName + "\" returned ANY of type " + + OUString::unacquired(&t.get()->pTypeName)); + } + auto const val = *static_cast< uno_Interface ** >(ret.getValue(ifc)); + if (val == nullptr) { + throw css::uno::RuntimeException( + "initial object queryInterface for OID \"" + sInstanceName + + "\" returned null css.uno.XInterface ANY"); + } return css::uno::Reference< css::uno::XInterface >( static_cast< css::uno::XInterface * >( binaryToCppMapping_.mapInterface( - *static_cast< uno_Interface ** >(ret.getValue(ifc)), + val, ifc.get())), SAL_NO_ACQUIRE); } -- cgit