sfx2/source/appl/appopen.cxx               |    5 +++--
 sfx2/source/doc/objserv.cxx                |    6 +++++-
 sfx2/source/notebookbar/SfxNotebookBar.cxx |   14 +++++++++-----
 3 files changed, 17 insertions(+), 8 deletions(-)

New commits:
commit 95d3e0d478686c7fa84f0bb8c466a1082333a47b
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Fri Apr 26 10:20:56 2024 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Mon Apr 29 09:27:38 2024 +0200

    SfxViewFrame::Current() dereferenced without null check
    
    found with msvc -analyze and _Ret_maybenull_
    
    Change-Id: Ia377822e93448dc61acd1482d34167c35a46836b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166705
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sfx2/source/appl/appopen.cxx b/sfx2/source/appl/appopen.cxx
index 03ad8039be7b..7ea6fca57d8d 100644
--- a/sfx2/source/appl/appopen.cxx
+++ b/sfx2/source/appl/appopen.cxx
@@ -1044,9 +1044,10 @@ void SfxApplication::OpenDocExec_Impl( SfxRequest& rReq )
     if( aFileName.startsWith("#") ) // Mark without URL
     {
         SfxViewFrame *pView = pTargetFrame ? 
pTargetFrame->GetCurrentViewFrame() : nullptr;
-        if ( !pView )
+        if (!pView)
             pView = SfxViewFrame::Current();
-        pView->GetViewShell()->JumpToMark( aFileName.copy(1) );
+        if (pView)
+            pView->GetViewShell()->JumpToMark( aFileName.copy(1) );
         rReq.SetReturnValue( SfxViewFrameItem( pView ) );
         return;
     }
diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx
index 9e0b2697cd74..d721458beb3b 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -452,6 +452,10 @@ static void sendErrorToLOK(ErrCodeMsg error)
     if (error.GetCode().GetClass() == ErrCodeClass::NONE)
         return;
 
+    SfxViewShell* pNotifier = SfxViewShell::Current();
+    if (!pNotifier)
+        return;
+
     boost::property_tree::ptree aTree;
     aTree.put("code", error);
     aTree.put("kind", "");
@@ -464,7 +468,7 @@ static void sendErrorToLOK(ErrCodeMsg error)
     std::stringstream aStream;
     boost::property_tree::write_json(aStream, aTree);
 
-    SfxViewShell::Current()->libreOfficeKitViewCallback(LOK_CALLBACK_ERROR, 
OString(aStream.str()));
+    pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_ERROR, 
OString(aStream.str()));
 }
 
 namespace
diff --git a/sfx2/source/notebookbar/SfxNotebookBar.cxx 
b/sfx2/source/notebookbar/SfxNotebookBar.cxx
index 41ae9c3c2666..42f11191d057 100644
--- a/sfx2/source/notebookbar/SfxNotebookBar.cxx
+++ b/sfx2/source/notebookbar/SfxNotebookBar.cxx
@@ -480,6 +480,9 @@ bool SfxNotebookBar::StateMethod(SystemWindow* pSysWindow,
 
             if (bIsLOK)
             {
+                if (!pViewShell)
+                    return false;
+
                 // Notebookbar was loaded too early what caused:
                 //   * in LOK: Paste Special feature was incorrectly 
initialized
                 // Skip first request so Notebookbar will be initialized after 
document was loaded
@@ -672,11 +675,12 @@ void SfxNotebookBar::ToggleMenubar()
 
 void SfxNotebookBar::ReloadNotebookBar(std::u16string_view sUIPath)
 {
-    if (SfxNotebookBar::IsActive())
-    {
-        SfxViewShell* pViewShell = SfxViewShell::Current();
-        
sfx2::SfxNotebookBar::StateMethod(pViewShell->GetViewFrame().GetBindings(), 
sUIPath, true);
-    }
+    if (!SfxNotebookBar::IsActive())
+        return;
+    SfxViewShell* pViewShell = SfxViewShell::Current();
+    if (!pViewShell)
+        return;
+    
sfx2::SfxNotebookBar::StateMethod(pViewShell->GetViewFrame().GetBindings(), 
sUIPath, true);
 }
 
 IMPL_STATIC_LINK(SfxNotebookBar, VclDisposeHdl, const SfxViewShell*, 
pViewShell, void)

Reply via email to