sfx2/source/doc/objmisc.cxx |    6 ++++++
 sfx2/source/doc/objserv.cxx |   10 ++++++++++
 sfx2/source/doc/objstor.cxx |    2 ++
 3 files changed, 18 insertions(+)

New commits:
commit 0cf325d41996444c33a4d9d3b7d37d05ef9a398c
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Tue Jul 2 13:24:38 2024 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Aug 16 08:55:12 2024 +0200

    sfx2: SfxObjectShell should not trust any signature on repaired package
    
    Change-Id: I0317f80989e9dabd23e88e3caab26ede3fb5bd56
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169883
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit 8b333575ee680664fa3d83249ccec90881754ad7)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169930
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171910
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx
index 078ae0c0a5bd..fc80221927a3 100644
--- a/sfx2/source/doc/objmisc.cxx
+++ b/sfx2/source/doc/objmisc.cxx
@@ -939,6 +939,12 @@ void SfxObjectShell::BreakMacroSign_Impl( bool 
bBreakMacroSign )
 
 void SfxObjectShell::CheckSecurityOnLoading_Impl()
 {
+    if (GetErrorCode() == ERRCODE_IO_BROKENPACKAGE)
+    {   // safety first: don't run any macros from broken package.
+        pImpl->aMacroMode.disallowMacroExecution();
+        return; // do not get signature status - needs to be done after 
RepairPackage
+    }
+
     // make sure LO evaluates the macro signatures, so it can be preserved
     GetScriptingSignatureState();
 
diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx
index 1591b27d6d74..d0edd54c9069 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -1859,6 +1859,16 @@ SignatureState SfxObjectShell::ImplGetSignatureState( 
bool bScriptingContent )
 
         uno::Sequence< security::DocumentSignatureInformation > aInfos = 
GetDocumentSignatureInformation( bScriptingContent );
         *pState = DocumentSignatures::getSignatureState(aInfos);
+
+        // repaired package cannot be trusted
+        if (*pState != SignatureState::NOSIGNATURES)
+        {
+            SfxBoolItem const*const 
pRepairItem{GetMedium()->GetItemSet()->GetItem(SID_REPAIRPACKAGE, false)};
+            if (pRepairItem && pRepairItem->GetValue())
+            {
+                *pState = SignatureState::BROKEN;
+            }
+        }
     }
 
     if ( *pState == SignatureState::OK || *pState == 
SignatureState::NOTVALIDATED
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index 7f8401cc2ee8..f9a3bafcbcbc 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -380,6 +380,8 @@ void SfxObjectShell::PrepareSecondTryLoad_Impl()
 {
     // only for internal use
     pImpl->m_xDocStorage.clear();
+    pImpl->nDocumentSignatureState = SignatureState::UNKNOWN;
+    pImpl->nScriptingSignatureState = SignatureState::UNKNOWN;
     pImpl->m_bIsInit = false;
     ResetError();
 }

Reply via email to