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 f62a49d95c437858836d7f305924cb334be36e9a
Author:     Caolán McNamara <[email protected]>
AuthorDate: Mon Apr 15 19:30:18 2024 +0100
Commit:     Caolán McNamara <[email protected]>
CommitDate: Tue Apr 16 13:08:49 2024 +0200

    null-deref in SfxViewShell::isBlockedCommand
    
    Change-Id: I43db7fabcc32971f951cc72dc9b1d22eba8df357
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166135
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Caolán McNamara <[email protected]>

diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index 212c63a419c1..83caa453e837 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -455,7 +455,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 47d88aafbf2f..12a96f8f90e3 100644
--- a/sfx2/source/control/unoctitm.cxx
+++ b/sfx2/source/control/unoctitm.cxx
@@ -546,18 +546,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.extractData());
-        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.extractData());
+            return;
+        }
     }
 
     if (
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index 22c05d26946c..800c3654cc25 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -3917,7 +3917,7 @@ void SfxViewShell::setBlockedCommandList(const char* 
blockedCommandList)
     }
 }
 
-bool SfxViewShell::isBlockedCommand(OUString command)
+bool SfxViewShell::isBlockedCommand(OUString command) const
 {
     return mvLOKBlockedCommandList.find(command) != 
mvLOKBlockedCommandList.end();
 }

Reply via email to