From c39abee181bedf8945dd8a85e52cc89dae4f83f6 Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Thu, 18 Nov 2021 14:13:35 -0800 Subject: [PATCH] Don't crash if a plugin has invalid QML Signed-off-by: Louise Poubel --- src/Application.cc | 3 ++ src/Application_TEST.cc | 8 ++++++ test/plugins/CMakeLists.txt | 1 + test/plugins/TestInvalidQmlPlugin.cc | 38 +++++++++++++++++++++++++ test/plugins/TestInvalidQmlPlugin.hh | 40 +++++++++++++++++++++++++++ test/plugins/TestInvalidQmlPlugin.qml | 21 ++++++++++++++ test/plugins/TestInvalidQmlPlugin.qrc | 5 ++++ 7 files changed, 116 insertions(+) create mode 100644 test/plugins/TestInvalidQmlPlugin.cc create mode 100644 test/plugins/TestInvalidQmlPlugin.hh create mode 100644 test/plugins/TestInvalidQmlPlugin.qml create mode 100644 test/plugins/TestInvalidQmlPlugin.qrc diff --git a/src/Application.cc b/src/Application.cc index 3d9ecd301..ac60ce07a 100644 --- a/src/Application.cc +++ b/src/Application.cc @@ -387,6 +387,9 @@ bool Application::LoadPlugin(const std::string &_filename, else plugin->Load(_pluginElem); + if (nullptr == plugin->CardItem()) + return false; + // Store plugin in queue to be added to the window this->dataPtr->pluginsToAdd.push(plugin); diff --git a/src/Application_TEST.cc b/src/Application_TEST.cc index ddd5e6b6a..5d575a3c9 100644 --- a/src/Application_TEST.cc +++ b/src/Application_TEST.cc @@ -136,6 +136,14 @@ TEST(ApplicationTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(LoadPlugin)) EXPECT_FALSE(app.LoadPlugin("TestNotRegisteredPlugin")); } + + // Plugin with invalid QML + { + Application app(g_argc, g_argv); + app.AddPluginPath(std::string(PROJECT_BINARY_PATH) + "/lib"); + + EXPECT_FALSE(app.LoadPlugin("TestInvalidQmlPlugin")); + } } ////////////////////////////////////////////////// diff --git a/test/plugins/CMakeLists.txt b/test/plugins/CMakeLists.txt index 7451a7329..5381233cc 100644 --- a/test/plugins/CMakeLists.txt +++ b/test/plugins/CMakeLists.txt @@ -11,6 +11,7 @@ link_directories( set (plugins TestBadInheritancePlugin + TestInvalidQmlPlugin TestNotRegisteredPlugin TestPlugin ) diff --git a/test/plugins/TestInvalidQmlPlugin.cc b/test/plugins/TestInvalidQmlPlugin.cc new file mode 100644 index 000000000..c4b604799 --- /dev/null +++ b/test/plugins/TestInvalidQmlPlugin.cc @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2021 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ + +#include + +#include "TestInvalidQmlPlugin.hh" + +using namespace ignition; +using namespace gui; + +///////////////////////////////////////////////// +TestInvalidQmlPlugin::TestInvalidQmlPlugin() + : Plugin() +{ +} + +///////////////////////////////////////////////// +TestInvalidQmlPlugin::~TestInvalidQmlPlugin() +{ +} + +// Register this plugin +IGNITION_ADD_PLUGIN(ignition::gui::TestInvalidQmlPlugin, + ignition::gui::Plugin) diff --git a/test/plugins/TestInvalidQmlPlugin.hh b/test/plugins/TestInvalidQmlPlugin.hh new file mode 100644 index 000000000..412dbd1e6 --- /dev/null +++ b/test/plugins/TestInvalidQmlPlugin.hh @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2021 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ + +#ifndef IGNITION_GUI_TEST_MALFORMEDPLUGIN_HH_ +#define IGNITION_GUI_TEST_MALFORMEDPLUGIN_HH_ + +#include + +namespace ignition +{ + namespace gui + { + class TestInvalidQmlPlugin : public Plugin + { + Q_OBJECT + + /// \brief Constructor + public: TestInvalidQmlPlugin(); + + /// \brief Destructor + public: virtual ~TestInvalidQmlPlugin(); + }; + } +} + +#endif diff --git a/test/plugins/TestInvalidQmlPlugin.qml b/test/plugins/TestInvalidQmlPlugin.qml new file mode 100644 index 000000000..17cdc890e --- /dev/null +++ b/test/plugins/TestInvalidQmlPlugin.qml @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2021 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ +import QtQuick 2.9 + +Rectangle { + banana: fail +} diff --git a/test/plugins/TestInvalidQmlPlugin.qrc b/test/plugins/TestInvalidQmlPlugin.qrc new file mode 100644 index 000000000..c48ea9d64 --- /dev/null +++ b/test/plugins/TestInvalidQmlPlugin.qrc @@ -0,0 +1,5 @@ + + + TestInvalidQmlPlugin.qml + +