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 5d111672ae58e35b7856bc2578352ebdc3ab6ecd Author: Caolán McNamara <caolan.mcnam...@collabora.com> AuthorDate: Mon Apr 15 19:30:18 2024 +0100 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Mon Apr 15 22:17:19 2024 +0200 null-deref in SfxViewShell::isBlockedCommand Change-Id: I43db7fabcc32971f951cc72dc9b1d22eba8df357 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166094 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx index ea7d345b29c4..3ebd2f4ec72f 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(const std::shared_ptr<SfxStoringHelper>& xHelper) { m_xHelper = xHelper; } diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx index f49dc2d7336f..9cbd29034a46 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 0c800e1092d7..52761a1fb5fb 100644 --- a/sfx2/source/view/viewsh.cxx +++ b/sfx2/source/view/viewsh.cxx @@ -3908,7 +3908,7 @@ void SfxViewShell::setBlockedCommandList(const char* blockedCommandList) } } -bool SfxViewShell::isBlockedCommand(OUString command) +bool SfxViewShell::isBlockedCommand(OUString command) const { return mvLOKBlockedCommandList.find(command) != mvLOKBlockedCommandList.end(); }