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 <plubius@neooffice.org>
This commit is contained in:
Patrick Luby
2023-08-01 14:27:49 +02:00
parent 0004de1492
commit 01a1d2a849
2 changed files with 14 additions and 1 deletions
@@ -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;
}
}
}
}
-1
View File
@@ -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();