Gui: Don't allow manipulator to delete the menubar

Same for the toolbar or context menu.
This commit is contained in:
Chris Hennes
2025-03-20 21:50:34 -05:00
committed by Benjamin Nauck
parent 00e648220a
commit 28e07eeda5

View File

@@ -26,8 +26,11 @@
#include "WorkbenchManipulatorPython.h"
#include "MenuManager.h"
#include "ToolBarManager.h"
#include <Base/Console.h>
#include <Base/Interpreter.h>
FC_LOG_LEVEL_INIT("WorkbenchManipulatorPython", true, true)
using namespace Gui;
void WorkbenchManipulatorPython::installManipulator(const Py::Object& obj)
@@ -153,6 +156,11 @@ void WorkbenchManipulatorPython::tryModifyMenuBar(const Py::Dict& dict, MenuItem
std::string command = static_cast<std::string>(Py::String(dict.getItem(remove)));
if (auto par = menuBar->findParentOf(command)) {
if (MenuItem* item = par->findItem(command)) {
if (item == menuBar) {
// Can't remove the menubar itself - Coverity issue 512853
FC_WARN("Cannot remove top-level menubar");
return;
}
par->removeItem(item);
delete item; // NOLINT
}
@@ -310,6 +318,11 @@ void WorkbenchManipulatorPython::tryModifyToolBar(const Py::Dict& dict, ToolBarI
else {
for (auto it : toolBar->getItems()) {
if (ToolBarItem* item = it->findItem(command)) {
if (item == toolBar) {
// Can't remove the toolBar itself - Coverity issue 513838
FC_WARN("Cannot remove top-level toolbar");
return;
}
it->removeItem(item);
delete item; // NOLINT
break;