[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - vcl/source

Gabriel Masei (via logerrit) logerrit at kemper.freedesktop.org
Sat Jun 12 05:31:06 UTC 2021


 vcl/source/window/mouse.cxx   |   19 ++++++++++------
 vcl/source/window/toolbox.cxx |    4 +--
 vcl/source/window/winproc.cxx |   47 +++++++++++++++++++++++++-----------------
 3 files changed, 43 insertions(+), 27 deletions(-)

New commits:
commit 5a1c5c9495f31820d55ba77b0cf5dfe10ab0e6f7
Author:     Gabriel Masei <gabriel.masei at 1and1.ro>
AuthorDate: Fri May 28 14:37:52 2021 +0300
Commit:     Dennis Francis <dennis.francis at collabora.com>
CommitDate: Sat Jun 12 07:30:30 2021 +0200

    vcl: check mpWindowImpl before referencing it.
    
    Fixed some cases generating crashes because mpWindowImpl was not checked for nullptr.
    
    Change-Id: I5540f9f21a870b02655b5bf2afdbf3a8153c1519
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116466
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Dennis Francis <dennis.francis at collabora.com>

diff --git a/vcl/source/window/mouse.cxx b/vcl/source/window/mouse.cxx
index 16993d199987..e2f0458bf0fe 100644
--- a/vcl/source/window/mouse.cxx
+++ b/vcl/source/window/mouse.cxx
@@ -252,7 +252,7 @@ void Window::ImplGrabFocus( GetFocusFlags nFlags )
 
     bool bAsyncFocusWaiting = false;
     vcl::Window *pFrame = pSVData->maFrameData.mpFirstFrame;
-    while( pFrame  )
+    while( pFrame && pFrame->mpWindowImpl && pFrame->mpWindowImpl->mpFrameData )
     {
         if( pFrame != mpWindowImpl->mpFrameWindow.get() && pFrame->mpWindowImpl->mpFrameData->mnFocusId )
         {
@@ -275,6 +275,8 @@ void Window::ImplGrabFocus( GetFocusFlags nFlags )
             bMustNotGrabFocus = true;
             break;
         }
+        if (!pParent->mpWindowImpl)
+            break;
         pParent = pParent->mpWindowImpl->mpParent;
     }
 
@@ -332,13 +334,16 @@ void Window::ImplGrabFocus( GetFocusFlags nFlags )
     else
     {
         vcl::Window* pNewOverlapWindow = ImplGetFirstOverlapWindow();
-        vcl::Window* pNewRealWindow = pNewOverlapWindow->ImplGetWindow();
-        pNewOverlapWindow->mpWindowImpl->mbActive = true;
-        pNewOverlapWindow->Activate();
-        if ( pNewRealWindow != pNewOverlapWindow )
+        if ( pNewOverlapWindow && pNewOverlapWindow->mpWindowImpl )
         {
-            pNewRealWindow->mpWindowImpl->mbActive = true;
-            pNewRealWindow->Activate();
+            vcl::Window* pNewRealWindow = pNewOverlapWindow->ImplGetWindow();
+            pNewOverlapWindow->mpWindowImpl->mbActive = true;
+            pNewOverlapWindow->Activate();
+            if ( pNewRealWindow != pNewOverlapWindow  && pNewRealWindow && pNewRealWindow->mpWindowImpl )
+            {
+                pNewRealWindow->mpWindowImpl->mbActive = true;
+                pNewRealWindow->Activate();
+            }
         }
     }
 
diff --git a/vcl/source/window/toolbox.cxx b/vcl/source/window/toolbox.cxx
index e7a15643f111..0a255688dd46 100644
--- a/vcl/source/window/toolbox.cxx
+++ b/vcl/source/window/toolbox.cxx
@@ -3077,7 +3077,7 @@ void ToolBox::MouseMove( const MouseEvent& rMEvt )
         vcl::Window *pWin = pFocusWin->GetParent();
         while (pWin)
         {
-            if(pWin->ImplGetWindowImpl()->mbToolBox)
+            if(pWin->ImplGetWindowImpl() && pWin->ImplGetWindowImpl()->mbToolBox)
             {
                 bFocusWindowIsAToolBoxChild = true;
                 break;
@@ -3086,7 +3086,7 @@ void ToolBox::MouseMove( const MouseEvent& rMEvt )
         }
     }
 
-    if( bFocusWindowIsAToolBoxChild || (pFocusWin && pFocusWin->ImplGetWindowImpl()->mbToolBox && pFocusWin != this) )
+    if( bFocusWindowIsAToolBoxChild || (pFocusWin && pFocusWin->ImplGetWindowImpl() && pFocusWin->ImplGetWindowImpl()->mbToolBox && pFocusWin != this) )
         bDrawHotSpot = false;
 
     if ( mbSelection && bDrawHotSpot )
diff --git a/vcl/source/window/winproc.cxx b/vcl/source/window/winproc.cxx
index cd6e91b21f7e..fe3b8bee916d 100644
--- a/vcl/source/window/winproc.cxx
+++ b/vcl/source/window/winproc.cxx
@@ -810,17 +810,20 @@ static vcl::Window* ImplGetKeyInputWindow( vcl::Window* pWindow )
     vcl::Window* pChild = pSVData->mpWinData->mpFirstFloat;
     while (pChild)
     {
-        if (pChild->ImplGetWindowImpl()->mbFloatWin)
+        if (pChild->ImplGetWindowImpl())
         {
-            if (static_cast<FloatingWindow *>(pChild)->GrabsFocus())
-                break;
-        }
-        else if (pChild->ImplGetWindowImpl()->mbDockWin)
-        {
-            vcl::Window* pParent = pChild->GetWindow(GetWindowType::RealParent);
-            if (pParent && pParent->ImplGetWindowImpl()->mbFloatWin &&
-                static_cast<FloatingWindow *>(pParent)->GrabsFocus())
-                break;
+            if (pChild->ImplGetWindowImpl()->mbFloatWin)
+            {
+                if (static_cast<FloatingWindow *>(pChild)->GrabsFocus())
+                    break;
+            }
+            else if (pChild->ImplGetWindowImpl()->mbDockWin)
+            {
+                vcl::Window* pParent = pChild->GetWindow(GetWindowType::RealParent);
+                if (pParent && pParent->ImplGetWindowImpl()->mbFloatWin &&
+                    static_cast<FloatingWindow *>(pParent)->GrabsFocus())
+                    break;
+            }
         }
         pChild = pChild->GetParent();
     }
@@ -828,7 +831,7 @@ static vcl::Window* ImplGetKeyInputWindow( vcl::Window* pWindow )
     if (!pChild)
         pChild = pWindow;
 
-    pChild = pChild->ImplGetWindowImpl()->mpFrameData->mpFocusWin;
+    pChild = pChild->ImplGetWindowImpl() && pChild->ImplGetWindowImpl()->mpFrameData ? pChild->ImplGetWindowImpl()->mpFrameData->mpFocusWin.get() : nullptr;
 
     // no child - then no input
     if ( !pChild )
@@ -1735,6 +1738,9 @@ static void ImplActivateFloatingWindows( vcl::Window const * pWindow, bool bActi
 
 IMPL_LINK_NOARG(vcl::Window, ImplAsyncFocusHdl, void*, void)
 {
+    if (!ImplGetWindowImpl() || !ImplGetWindowImpl()->mpFrameData)
+        return;
+
     ImplGetWindowImpl()->mpFrameData->mnFocusId = nullptr;
 
     // If the status has been preserved, because we got back the focus
@@ -1793,22 +1799,27 @@ IMPL_LINK_NOARG(vcl::Window, ImplAsyncFocusHdl, void*, void)
             {
                 // transfer the FocusWindow
                 vcl::Window* pOverlapWindow = pFocusWin->ImplGetFirstOverlapWindow();
-                pOverlapWindow->ImplGetWindowImpl()->mpLastFocusWindow = pFocusWin;
+                if ( pOverlapWindow && pOverlapWindow->ImplGetWindowImpl() )
+                    pOverlapWindow->ImplGetWindowImpl()->mpLastFocusWindow = pFocusWin;
                 pSVData->mpWinData->mpFocusWin = nullptr;
 
-                if ( pFocusWin->ImplGetWindowImpl()->mpCursor )
+                if ( pFocusWin->ImplGetWindowImpl() && pFocusWin->ImplGetWindowImpl()->mpCursor )
                     pFocusWin->ImplGetWindowImpl()->mpCursor->ImplHide();
 
                 // call the Deactivate
                 vcl::Window* pOldOverlapWindow = pFocusWin->ImplGetFirstOverlapWindow();
                 vcl::Window* pOldRealWindow = pOldOverlapWindow->ImplGetWindow();
 
-                pOldOverlapWindow->ImplGetWindowImpl()->mbActive = false;
-                pOldOverlapWindow->Deactivate();
-                if ( pOldRealWindow != pOldOverlapWindow )
+                if (pOldOverlapWindow && pOldOverlapWindow->ImplGetWindowImpl() &&
+                    pOldRealWindow && pOldRealWindow->ImplGetWindowImpl())
                 {
-                    pOldRealWindow->ImplGetWindowImpl()->mbActive = false;
-                    pOldRealWindow->Deactivate();
+                    pOldOverlapWindow->ImplGetWindowImpl()->mbActive = false;
+                    pOldOverlapWindow->Deactivate();
+                    if ( pOldRealWindow != pOldOverlapWindow )
+                    {
+                        pOldRealWindow->ImplGetWindowImpl()->mbActive = false;
+                        pOldRealWindow->Deactivate();
+                    }
                 }
 
                 // TrackingMode is ended in ImplHandleLoseFocus


More information about the Libreoffice-commits mailing list