summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt K <mattkse@gmail.com>2024-01-13 18:12:16 -0600
committerAndras Timar <andras.timar@collabora.com>2024-01-15 16:27:16 +0100
commit8235d91a7f5dc00cc54196e2df6bfa70a103e2c1 (patch)
treedd09ec42f1a35b03564364b56a799ec5ad6f8f2b
parent1d2529494b1aa666e8d42cc0e001475c838ab355 (diff)
tdf#159171 Prevent crash after selecting unprotected cells 2 times
The problem is that the code tries to check for a table on a clip- board doc, but doesn't find any so it propagates nullptr back to the caller, which is then used without being checked thereby leading to a crash. The fix is to check the result of the table check of clipboard doc before doing any operations with it, thus preventing the crash. Change-Id: Ieb4a52d0c1cb713d5c14930e5e559e5bf520b330 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162033 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> (cherry picked from commit 3b10bbacb8a12a00c35683eeaae4a75046a84aac) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162091 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
-rw-r--r--sc/source/ui/app/transobj.cxx46
1 files changed, 26 insertions, 20 deletions
diff --git a/sc/source/ui/app/transobj.cxx b/sc/source/ui/app/transobj.cxx
index 6a1ef6a04650..5f0599c888b3 100644
--- a/sc/source/ui/app/transobj.cxx
+++ b/sc/source/ui/app/transobj.cxx
@@ -312,28 +312,34 @@ bool ScTransferObj::GetData( const datatransfer::DataFlavor& rFlavor, const OUSt
ScAddress aPos(nCol, nRow, nTab);
const ScPatternAttr* pPattern = m_pDoc->GetPattern( nCol, nRow, nTab );
- ScTabEditEngine aEngine( *pPattern, m_pDoc->GetEditPool(), m_pDoc.get() );
- ScRefCellValue aCell(*m_pDoc, aPos);
- if (aCell.getType() == CELLTYPE_EDIT)
+ if (pPattern)
{
- const EditTextObject* pObj = aCell.getEditText();
- aEngine.SetTextCurrentDefaults(*pObj);
- }
- else
- {
- SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
- sal_uInt32 nNumFmt = pPattern->GetNumberFormat(pFormatter);
- const Color* pColor;
- OUString aText = ScCellFormat::GetString(aCell, nNumFmt, &pColor, *pFormatter, *m_pDoc);
- if (!aText.isEmpty())
- aEngine.SetTextCurrentDefaults(aText);
- }
+ ScTabEditEngine aEngine(*pPattern, m_pDoc->GetEditPool(), m_pDoc.get());
+ ScRefCellValue aCell(*m_pDoc, aPos);
+ if (aCell.getType() == CELLTYPE_EDIT)
+ {
+ const EditTextObject* pObj = aCell.getEditText();
+ aEngine.SetTextCurrentDefaults(*pObj);
+ }
+ else
+ {
+ SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
+ sal_uInt32 nNumFmt = pPattern->GetNumberFormat(pFormatter);
+ const Color* pColor;
+ OUString aText
+ = ScCellFormat::GetString(aCell, nNumFmt, &pColor, *pFormatter, *m_pDoc);
+ if (!aText.isEmpty())
+ aEngine.SetTextCurrentDefaults(aText);
+ }
- bOK = SetObject( &aEngine,
- ((nFormat == SotClipboardFormatId::RTF) ? SCTRANS_TYPE_EDIT_RTF :
- ((nFormat == SotClipboardFormatId::EDITENGINE_ODF_TEXT_FLAT) ?
- SCTRANS_TYPE_EDIT_ODF_TEXT_FLAT : SCTRANS_TYPE_EDIT_BIN)),
- rFlavor );
+ bOK = SetObject(&aEngine,
+ ((nFormat == SotClipboardFormatId::RTF)
+ ? SCTRANS_TYPE_EDIT_RTF
+ : ((nFormat == SotClipboardFormatId::EDITENGINE_ODF_TEXT_FLAT)
+ ? SCTRANS_TYPE_EDIT_ODF_TEXT_FLAT
+ : SCTRANS_TYPE_EDIT_BIN)),
+ rFlavor);
+ }
}
else if ( ScImportExport::IsFormatSupported( nFormat ) || nFormat == SotClipboardFormatId::RTF
|| nFormat == SotClipboardFormatId::RICHTEXT )