sfx2: SfxObjectShell should not trust any signature on repaired package
authorMichael Stahl <michael.stahl@allotropia.de>
Tue, 2 Jul 2024 11:24:38 +0000 (13:24 +0200)
committerBastien Roucariès <rouca@debian.org>
Mon, 13 Jan 2025 22:18:17 +0000 (22:18 +0000)
[ELTS]
cast pointer like with similar code in context

Change-Id: I0317f80989e9dabd23e88e3caab26ede3fb5bd56
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169883
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
(cherry picked from commit 8b333575ee680664fa3d83249ccec90881754ad7)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169930
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171910
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Gbp-Pq: Name do-not-trust-any-signature-on-repaired-package.diff

sfx2/source/doc/objmisc.cxx
sfx2/source/doc/objserv.cxx
sfx2/source/doc/objstor.cxx

index cd733bc8edb2ca341e39285c8006c32c6e9d918e..b469c0b83e5f5ef3a95c2c5c24ad0366fd8c7888 100644 (file)
@@ -930,6 +930,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();
 
index 4f4eebd34a55c3efc111ffb3c78f8a10d41b11b3..ef39cca1100d91ddd3fe0c0187a097c89f345171 100644 (file)
@@ -1629,6 +1629,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{SfxItemSet::GetItem<SfxBoolItem>(GetMedium()->GetItemSet(), SID_REPAIRPACKAGE, false)};
+            if (pRepairItem && pRepairItem->GetValue())
+            {
+                *pState = SignatureState::BROKEN;
+            }
+        }
     }
 
     if ( *pState == SignatureState::OK || *pState == SignatureState::NOTVALIDATED
index a336822aa546234c6d26bd008e903a0b9221b3ac..1fca525c8e29383331904fd7851b5712d459c0cd 100644 (file)
@@ -372,6 +372,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();
 }