Skip to content

Commit

Permalink
Don't crash if a plugin has invalid QML
Browse files Browse the repository at this point in the history
Signed-off-by: Louise Poubel <[email protected]>
  • Loading branch information
chapulina committed Nov 18, 2021
1 parent 970914a commit c39abee
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 8 additions & 0 deletions src/Application_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}

//////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions test/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ link_directories(

set (plugins
TestBadInheritancePlugin
TestInvalidQmlPlugin
TestNotRegisteredPlugin
TestPlugin
)
Expand Down
38 changes: 38 additions & 0 deletions test/plugins/TestInvalidQmlPlugin.cc
Original file line number Diff line number Diff line change
@@ -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 <ignition/plugin/Register.hh>

#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)
40 changes: 40 additions & 0 deletions test/plugins/TestInvalidQmlPlugin.hh
Original file line number Diff line number Diff line change
@@ -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 <ignition/gui/Plugin.hh>

namespace ignition
{
namespace gui
{
class TestInvalidQmlPlugin : public Plugin
{
Q_OBJECT

/// \brief Constructor
public: TestInvalidQmlPlugin();

/// \brief Destructor
public: virtual ~TestInvalidQmlPlugin();
};
}
}

#endif
21 changes: 21 additions & 0 deletions test/plugins/TestInvalidQmlPlugin.qml
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 5 additions & 0 deletions test/plugins/TestInvalidQmlPlugin.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="TestInvalidQmlPlugin/">
<file>TestInvalidQmlPlugin.qml</file>
</qresource>
</RCC>

0 comments on commit c39abee

Please sign in to comment.