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

Gabriel Masei (via logerrit) logerrit at kemper.freedesktop.org
Wed Jun 9 09:01:41 UTC 2021


 vcl/source/window/mouse.cxx   |   19 ++++++++++------
 vcl/source/window/toolbox.cxx |    2 -
 vcl/source/window/winproc.cxx |   47 +++++++++++++++++++++++++-----------------
 3 files changed, 42 insertions(+), 26 deletions(-)

New commits:
commit 54916b178bdee9be0f3faef7b62aa735cb3d3ab5
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: Wed Jun 9 11:01:04 2021 +0200

    vcl: check mpWindowImpl before referencing it
    
    Fixed some cases generating crashes because mpWindowImpl was not checked for nullptr.
    
    Conflicts:
            vcl/source/window/toolbox.cxx
    
    Change-Id: I5540f9f21a870b02655b5bf2afdbf3a8153c1519
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116330
    Tested-by: Jenkins
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116774
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Gabriel Masei <gabriel.masei at 1and1.ro>
    Reviewed-by: Dennis Francis <dennis.francis at collabora.com>

diff --git a/vcl/source/window/mouse.cxx b/vcl/source/window/mouse.cxx
index 47116725856f..663da0ff872c 100644
--- a/vcl/source/window/mouse.cxx
+++ b/vcl/source/window/mouse.cxx
@@ -253,7 +253,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 )
         {
@@ -276,6 +276,8 @@ void Window::ImplGrabFocus( GetFocusFlags nFlags )
             bMustNotGrabFocus = true;
             break;
         }
+        if (!pParent->mpWindowImpl)
+            break;
         pParent = pParent->mpWindowImpl->mpParent;
     }
 
@@ -333,13 +335,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 ef8641986555..0d22f446dea7 100644
--- a/vcl/source/window/toolbox.cxx
+++ b/vcl/source/window/toolbox.cxx
@@ -3209,7 +3209,7 @@ void ToolBox::MouseMove( const MouseEvent& rMEvt )
     // and do not highlight when focus is in a different toolbox
     bool bDrawHotSpot = true;
     vcl::Window *pWin = Application::GetFocusWindow();
-    if( pWin && pWin->ImplGetWindowImpl()->mbToolBox && pWin != this )
+    if( pWin && pWin->ImplGetWindowImpl() && pWin->ImplGetWindowImpl()->mbToolBox && pWin != this )
         bDrawHotSpot = false;
 
     if ( mbSelection && bDrawHotSpot )
diff --git a/vcl/source/window/winproc.cxx b/vcl/source/window/winproc.cxx
index 31620bc6a0ac..4dea82046299 100644
--- a/vcl/source/window/winproc.cxx
+++ b/vcl/source/window/winproc.cxx
@@ -814,17 +814,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();
     }
@@ -832,7 +835,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 )
@@ -1740,6 +1743,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
@@ -1798,22 +1804,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