reportdesign/source/ui/report/ViewsWindow.cxx |   14 ++++++++++++++
 svx/source/svdraw/svdhdl.cxx                  |    1 -
 2 files changed, 14 insertions(+), 1 deletion(-)

New commits:
commit 01a1d2a84992973b8a0e5f1ae99fd32f5913b58f
Author:     Patrick Luby <plub...@neooffice.org>
AuthorDate: Mon Jul 31 20:03:13 2023 -0400
Commit:     Patrick Luby <plub...@neooffice.org>
CommitDate: Tue Aug 1 14:27:49 2023 +0200

    tdf#144072 prevent use of a deleted pointer
    
    BegDragObj_createInvisibleObjectAtPosition() may clear the handle
    list and that will delete the SdrHdl instances owned by this section
    view so set _pHdl to null if it has been deleted during the call.
    
    Change-Id: I89606958f8a76a2c35685d1aff6b0159739a464a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155119
    Tested-by: Jenkins
    Reviewed-by: Patrick Luby <plub...@neooffice.org>

diff --git a/reportdesign/source/ui/report/ViewsWindow.cxx 
b/reportdesign/source/ui/report/ViewsWindow.cxx
index e11735bf72ca..a5ad82e818e2 100644
--- a/reportdesign/source/ui/report/ViewsWindow.cxx
+++ b/reportdesign/source/ui/report/ViewsWindow.cxx
@@ -1043,7 +1043,21 @@ void OViewsWindow::BegDragObj(const Point& _aPnt, 
SdrHdl* _pHdl,const OSectionVi
                         "createInvisible X:" << aRect.Left() << " Y:"
                             << aRect.Top() << " on View #" << nViewCount);
 
+                    // tdf#144072 prevent use of a deleted pointer
+                    // BegDragObj_createInvisibleObjectAtPosition() may clear
+                    // the handle list and that will delete the SdrHdl 
instances
+                    // owned by this section view so set _pHdl to null if it 
has
+                    // been deleted during the call.
+                    bool bHdlInList = false;
+                    const SdrHdlList& rHdlList = rView.GetHdlList();
+                    if (_pHdl && rHdlList.GetHdlNum(_pHdl) < 
rHdlList.GetHdlCount())
+                        bHdlInList = true;
                     BegDragObj_createInvisibleObjectAtPosition(aRect, rView);
+                    if (bHdlInList && rHdlList.GetHdlNum(_pHdl) >= 
rHdlList.GetHdlCount())
+                    {
+                        SAL_WARN("reportdesign", "SdrHdl pointer parameter has 
been deleted");
+                        _pHdl = nullptr;
+                    }
                 }
             }
         }
diff --git a/svx/source/svdraw/svdhdl.cxx b/svx/source/svdraw/svdhdl.cxx
index de6ffcd8175f..3bcebf59ea26 100644
--- a/svx/source/svdraw/svdhdl.cxx
+++ b/svx/source/svdraw/svdhdl.cxx
@@ -2282,7 +2282,6 @@ size_t SdrHdlList::GetHdlNum(const SdrHdl* pHdl) const
         return SAL_MAX_SIZE;
     auto it = std::find_if( maList.begin(), maList.end(),
         [&](const std::unique_ptr<SdrHdl> & p) { return p.get() == pHdl; });
-    assert(it != maList.end());
     if( it == maList.end() )
         return SAL_MAX_SIZE;
     return it - maList.begin();

Reply via email to