sc/source/ui/app/transobj.cxx |   46 +++++++++++++++++++++++-------------------
 1 file changed, 26 insertions(+), 20 deletions(-)

New commits:
commit 87cf3f7fb877db5eca5aa7923586207920d19b79
Author:     Matt K <matt...@gmail.com>
AuthorDate: Sat Jan 13 18:12:16 2024 -0600
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Mon Jan 15 15:23:05 2024 +0100

    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.kagan...@collabora.com>
    (cherry picked from commit 3b10bbacb8a12a00c35683eeaae4a75046a84aac)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162091
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    (cherry picked from commit f5a6c7d5252b9d201a9e00c8d9f45f66114d1462)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162098

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 )

Reply via email to