include/sfx2/viewsh.hxx | 2 +- sfx2/source/control/unoctitm.cxx | 25 ++++++++++++++----------- sfx2/source/view/viewsh.cxx | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-)
New commits: commit da505b6ee43c8a39ae12d49483d25ac1819882e8 Author: Caolán McNamara <[email protected]> AuthorDate: Mon Apr 15 19:30:18 2024 +0100 Commit: Michael Meeks <[email protected]> CommitDate: Mon Apr 15 23:18:56 2024 +0200 null-deref in SfxViewShell::isBlockedCommand Change-Id: I43db7fabcc32971f951cc72dc9b1d22eba8df357 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166134 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Michael Meeks <[email protected]> diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx index 8b8a21f77741..e68f556c1072 100644 --- a/include/sfx2/viewsh.hxx +++ b/include/sfx2/viewsh.hxx @@ -485,7 +485,7 @@ public: // Blocked Command view settings void setBlockedCommandList(const char* blockedCommandList); - bool isBlockedCommand(OUString command); + bool isBlockedCommand(OUString command) const; void SetStoringHelper(std::shared_ptr<SfxStoringHelper> xHelper) { m_xHelper = xHelper; } diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx index b62f0f4376c4..d6d13f82f0a4 100644 --- a/sfx2/source/control/unoctitm.cxx +++ b/sfx2/source/control/unoctitm.cxx @@ -532,18 +532,21 @@ void SfxDispatchController_Impl::dispatch( const css::util::URL& aURL, SolarMutexGuard aGuard; - if (comphelper::LibreOfficeKit::isActive() && - SfxViewShell::Current()->isBlockedCommand(aURL.Complete)) + if (comphelper::LibreOfficeKit::isActive()) { - tools::JsonWriter aTree; - aTree.put("code", ""); - aTree.put("kind", "BlockedCommand"); - aTree.put("cmd", aURL.Complete); - aTree.put("message", "Blocked feature"); - aTree.put("viewID", SfxViewShell::Current()->GetViewShellId().get()); - - SfxViewShell::Current()->libreOfficeKitViewCallback(LOK_COMMAND_BLOCKED, aTree.finishAndGetAsOString()); - return; + const SfxViewShell* pViewShell = SfxViewShell::Current(); + if (pViewShell && pViewShell->isBlockedCommand(aURL.Complete)) + { + tools::JsonWriter aTree; + aTree.put("code", ""); + aTree.put("kind", "BlockedCommand"); + aTree.put("cmd", aURL.Complete); + aTree.put("message", "Blocked feature"); + aTree.put("viewID", pViewShell->GetViewShellId().get()); + + pViewShell->libreOfficeKitViewCallback(LOK_COMMAND_BLOCKED, aTree.finishAndGetAsOString()); + return; + } } if ( diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx index 5819cafd83a1..75731ecf1ccd 100644 --- a/sfx2/source/view/viewsh.cxx +++ b/sfx2/source/view/viewsh.cxx @@ -3913,7 +3913,7 @@ void SfxViewShell::setBlockedCommandList(const char* blockedCommandList) } } -bool SfxViewShell::isBlockedCommand(OUString command) +bool SfxViewShell::isBlockedCommand(OUString command) const { return mvLOKBlockedCommandList.find(command) != mvLOKBlockedCommandList.end(); }
