35e961
From 3831e68bffc233f581e3eb1cb3c7ed925daab86f Mon Sep 17 00:00:00 2001
35e961
From: Stephan Bergmann <sbergman@redhat.com>
35e961
Date: Tue, 30 Aug 2022 14:04:52 +0200
35e961
Subject: [PATCH] Filter out unwanted command URIs
35e961
MIME-Version: 1.0
35e961
Content-Type: text/plain; charset=UTF-8
35e961
Content-Transfer-Encoding: 8bit
35e961
35e961
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139225
35e961
Tested-by: Jenkins
35e961
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
35e961
(cherry picked from commit 27d29f7df428885865a8e2313283839b20f2a34b)
35e961
Conflicts:
35e961
	desktop/source/app/cmdlineargs.cxx
35e961
35e961
Change-Id: I0b7e5329af8cc053d14d5c60ec14fe7f364ef993
35e961
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139182
35e961
Tested-by: Jenkins
35e961
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
35e961
(cherry picked from commit da291e2960b75153f41d440a1b41961567432e8c)
35e961
35e961
These commands are always URLs already
35e961
35e961
Change-Id: I5083765c879689d7f933bbe00ad70bb68e635a21
35e961
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139042
35e961
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
35e961
Tested-by: Jenkins
35e961
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
35e961
(cherry picked from commit e61701e1ee6763de72b397e6ade1124eca9400f3)
35e961
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138980
35e961
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
35e961
(cherry picked from commit 5b4025bb56999f5c895c6f7e0b52f521800d65b0)
35e961
35e961
check IFrame "FrameURL" target
35e961
35e961
similiar to
35e961
35e961
commit b3edf85e0fe6ca03dc26e1bf531be82193bc9627
35e961
Date:   Wed Aug 7 17:37:11 2019 +0100
35e961
35e961
    warn on load when a document binds an event to a macro
35e961
35e961
Change-Id: Iea888b1c083d2dc69ec322309ac9ae8c5e5eb315
35e961
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139059
35e961
Tested-by: Jenkins
35e961
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
35e961
(cherry picked from commit c7450d0b9d02c64ae3da467d329040787039767e)
35e961
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139117
35e961
Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
35e961
(cherry picked from commit f5e3b0a7966d7d28817292adbb58fb43f28b7c6d)
35e961
35e961
check impress/calc IFrame "FrameURL" target
35e961
35e961
similar to
35e961
35e961
commit c7450d0b9d02c64ae3da467d329040787039767e
35e961
Date:   Tue Aug 30 17:01:08 2022 +0100
35e961
35e961
    check IFrame "FrameURL" target
35e961
35e961
Change-Id: Ibf28c29acb4476830431d02772f3ecd4b23a6a27
35e961
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139495
35e961
Tested-by: Jenkins
35e961
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
35e961
(cherry picked from commit d0312786571221c2dd4f63fa69f6f0489d7d39ec)
35e961
---
35e961
 desktop/source/app/cmdlineargs.cxx   | 10 +++++++++-
35e961
 sfx2/source/appl/macroloader.cxx     |  9 +++++++--
35e961
 sfx2/source/doc/iframe.cxx           | 21 ++++++++++++++++-----
35e961
 sfx2/source/inc/macroloader.hxx      |  2 ++
35e961
 sw/source/filter/html/htmlplug.cxx   |  7 ++++++-
35e961
 sw/source/filter/xml/xmltexti.cxx    |  9 +++++++--
35e961
 wizards/source/access2base/DoCmd.xba |  2 +-
35e961
 xmloff/source/draw/ximpshap.cxx      |  4 ++++
35e961
 8 files changed, 52 insertions(+), 12 deletions(-)
35e961
35e961
diff --git a/desktop/source/app/cmdlineargs.cxx b/desktop/source/app/cmdlineargs.cxx
35e961
index 381147c..5babfbe 100644
35e961
--- a/desktop/source/app/cmdlineargs.cxx
35e961
+++ b/desktop/source/app/cmdlineargs.cxx
35e961
@@ -27,6 +27,7 @@
35e961
 
35e961
 #include "cmdlineargs.hxx"
35e961
 #include <tools/stream.hxx>
35e961
+#include <tools/urlobj.hxx>
35e961
 #include <vcl/svapp.hxx>
35e961
 #include <rtl/uri.hxx>
35e961
 #include <rtl/ustring.hxx>
35e961
@@ -169,7 +170,14 @@ CommandLineEvent CheckOfficeURI(/* in,out */ OUString& arg, CommandLineEvent cur
35e961
     }
35e961
     if (nURIlen < 0)
35e961
         nURIlen = rest2.getLength();
35e961
-    arg = rest2.copy(0, nURIlen);
35e961
+    auto const uri = rest2.copy(0, nURIlen);
35e961
+    if (INetURLObject(uri).GetProtocol() == INetProtocol::Macro) {
35e961
+        // Let the "Open" machinery process the full command URI (leading to failure, by intention,
35e961
+        // as the "Open" machinery does not know about those command URI schemes):
35e961
+        curEvt = CommandLineEvent::Open;
35e961
+    } else {
35e961
+        arg = uri;
35e961
+    }
35e961
     return curEvt;
35e961
 }
35e961
 
35e961
diff --git a/sfx2/source/appl/macroloader.cxx b/sfx2/source/appl/macroloader.cxx
35e961
index 98e036e..b50d1e6 100644
35e961
--- a/sfx2/source/appl/macroloader.cxx
35e961
+++ b/sfx2/source/appl/macroloader.cxx
35e961
@@ -76,10 +76,10 @@ css::uno::Sequence<OUString> SAL_CALL SfxMacroLoader::getSupportedServiceNames()
35e961
     return aSeq;
35e961
 }
35e961
 
35e961
-SfxObjectShell* SfxMacroLoader::GetObjectShell_Impl()
35e961
+SfxObjectShell* SfxMacroLoader::GetObjectShell(const Reference <XFrame>& xFrame)
35e961
 {
35e961
     SfxObjectShell* pDocShell = nullptr;
35e961
-    Reference < XFrame > xFrame( m_xFrame.get(), UNO_QUERY );
35e961
+
35e961
     if ( xFrame.is() )
35e961
     {
35e961
         SfxFrame* pFrame=nullptr;
35e961
@@ -96,6 +96,11 @@ SfxObjectShell* SfxMacroLoader::GetObjectShell_Impl()
35e961
     return pDocShell;
35e961
 }
35e961
 
35e961
+SfxObjectShell* SfxMacroLoader::GetObjectShell_Impl()
35e961
+{
35e961
+    Reference < XFrame > xFrame( m_xFrame.get(), UNO_QUERY );
35e961
+    return SfxMacroLoader::GetObjectShell(xFrame);
35e961
+}
35e961
 
35e961
 uno::Reference<frame::XDispatch> SAL_CALL SfxMacroLoader::queryDispatch(
35e961
     const util::URL&   aURL            ,
35e961
diff --git a/sfx2/source/doc/iframe.cxx b/sfx2/source/doc/iframe.cxx
35e961
index 8b12715..b5291b2 100644
35e961
--- a/sfx2/source/doc/iframe.cxx
35e961
+++ b/sfx2/source/doc/iframe.cxx
35e961
@@ -39,11 +39,13 @@
35e961
 #include <svl/ownlist.hxx>
35e961
 #include <svl/itemprop.hxx>
35e961
 #include <sfx2/frmdescr.hxx>
35e961
+#include <sfx2/objsh.hxx>
35e961
 #include <sfx2/sfxdlg.hxx>
35e961
 #include <sfx2/sfxsids.hrc>
35e961
 #include <toolkit/helper/vclunohelper.hxx>
35e961
 #include <vcl/window.hxx>
35e961
 #include <tools/debug.hxx>
35e961
+#include <macroloader.hxx>
35e961
 
35e961
 using namespace ::com::sun::star;
35e961
 
35e961
@@ -159,6 +161,19 @@ sal_Bool SAL_CALL IFrameObject::load(
35e961
 {
35e961
     if ( SvtMiscOptions().IsPluginsEnabled() )
35e961
     {
35e961
+        util::URL aTargetURL;
35e961
+        aTargetURL.Complete = maFrmDescr.GetURL().GetMainURL( INetURLObject::DecodeMechanism::NONE );
35e961
+        uno::Reference < util::XURLTransformer > xTrans( util::URLTransformer::create( mxContext ) );
35e961
+        xTrans->parseStrict( aTargetURL );
35e961
+
35e961
+        if (INetURLObject(aTargetURL.Complete).GetProtocol() == INetProtocol::Macro)
35e961
+        {
35e961
+            uno::Reference<frame::XFramesSupplier> xParentFrame = xFrame->getCreator();
35e961
+            SfxObjectShell* pDoc = SfxMacroLoader::GetObjectShell(xParentFrame);
35e961
+            if (pDoc && !pDoc->AdjustMacroMode())
35e961
+                return false;
35e961
+        }
35e961
+
35e961
         DBG_ASSERT( !mxFrame.is(), "Frame already existing!" );
35e961
         VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
35e961
         VclPtr<IFrameWindow_Impl> pWin = VclPtr<IFrameWindow_Impl>::Create( pParent, maFrmDescr.IsFrameBorderOn() );
35e961
@@ -181,16 +196,12 @@ sal_Bool SAL_CALL IFrameObject::load(
35e961
         if ( xFramesSupplier.is() )
35e961
             mxFrame->setCreator( xFramesSupplier );
35e961
 
35e961
-        util::URL aTargetURL;
35e961
-        aTargetURL.Complete = maFrmDescr.GetURL().GetMainURL( INetURLObject::DecodeMechanism::NONE );
35e961
-        uno::Reference < util::XURLTransformer > xTrans( util::URLTransformer::create( mxContext ) );
35e961
-        xTrans->parseStrict( aTargetURL );
35e961
-
35e961
         uno::Sequence < beans::PropertyValue > aProps(2);
35e961
         aProps[0].Name = "PluginMode";
35e961
         aProps[0].Value <<= sal_Int16(2);
35e961
         aProps[1].Name = "ReadOnly";
35e961
         aProps[1].Value <<= true;
35e961
+
35e961
         uno::Reference < frame::XDispatch > xDisp = mxFrame->queryDispatch( aTargetURL, "_self", 0 );
35e961
         if ( xDisp.is() )
35e961
             xDisp->dispatch( aTargetURL, aProps );
35e961
diff --git a/sfx2/source/inc/macroloader.hxx b/sfx2/source/inc/macroloader.hxx
35e961
index 9e1dfba..b3e7a5e 100644
35e961
--- a/sfx2/source/inc/macroloader.hxx
35e961
+++ b/sfx2/source/inc/macroloader.hxx
35e961
@@ -82,6 +82,8 @@ public:
35e961
     virtual void SAL_CALL addStatusListener( const css::uno::Reference< css::frame::XStatusListener >& xControl, const css::util::URL& aURL ) override;
35e961
 
35e961
     virtual void SAL_CALL removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >& xControl, const css::util::URL& aURL ) override;
35e961
+
35e961
+    static SfxObjectShell* GetObjectShell(const css::uno::Reference<css::frame::XFrame>& xFrame);
35e961
 };
35e961
 
35e961
 #endif
35e961
diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx
35e961
index a0da671..eb70704 100644
35e961
--- a/sw/source/filter/html/htmlplug.cxx
35e961
+++ b/sw/source/filter/html/htmlplug.cxx
35e961
@@ -1087,7 +1087,12 @@ void SwHTMLParser::InsertFloatingFrame()
35e961
                 bool bHasBorder = aFrameDesc.HasFrameBorder();
35e961
                 Size aMargin = aFrameDesc.GetMargin();
35e961
 
35e961
-                xSet->setPropertyValue("FrameURL", uno::makeAny( aFrameDesc.GetURL().GetMainURL( INetURLObject::DecodeMechanism::NONE ) ) );
35e961
+                OUString sHRef = aFrameDesc.GetURL().GetMainURL( INetURLObject::DecodeMechanism::NONE );
35e961
+
35e961
+                if (INetURLObject(sHRef).GetProtocol() == INetProtocol::Macro)
35e961
+                    NotifyMacroEventRead();
35e961
+
35e961
+                xSet->setPropertyValue("FrameURL", uno::makeAny( sHRef ) );
35e961
                 xSet->setPropertyValue("FrameName", uno::makeAny( aName ) );
35e961
 
35e961
                 if ( eScroll == ScrollingMode::Auto )
35e961
diff --git a/sw/source/filter/xml/xmltexti.cxx b/sw/source/filter/xml/xmltexti.cxx
35e961
index 788bec5..72a14b9 100644
35e961
--- a/sw/source/filter/xml/xmltexti.cxx
35e961
+++ b/sw/source/filter/xml/xmltexti.cxx
35e961
@@ -853,9 +853,14 @@ uno::Reference< XPropertySet > SwXMLTextImportHelper::createAndInsertFloatingFra
35e961
             uno::Reference < beans::XPropertySet > xSet( xObj->getComponent(), uno::UNO_QUERY );
35e961
             if ( xSet.is() )
35e961
             {
35e961
+                OUString sHRef = URIHelper::SmartRel2Abs(
35e961
+                            INetURLObject( GetXMLImport().GetBaseURL() ), rHRef );
35e961
+
35e961
+                if (INetURLObject(sHRef).GetProtocol() == INetProtocol::Macro)
35e961
+                    GetXMLImport().NotifyMacroEventRead();
35e961
+
35e961
                 xSet->setPropertyValue("FrameURL",
35e961
-                    makeAny( URIHelper::SmartRel2Abs(
35e961
-                            INetURLObject( GetXMLImport().GetBaseURL() ), rHRef ) ) );
35e961
+                    makeAny( rHRef ) );
35e961
 
35e961
                 xSet->setPropertyValue("FrameName",
35e961
                     makeAny( rName ) );
35e961
diff --git a/wizards/source/access2base/DoCmd.xba b/wizards/source/access2base/DoCmd.xba
35e961
index 27b0d74..26755a8 100644
35e961
--- a/wizards/source/access2base/DoCmd.xba
35e961
+++ b/wizards/source/access2base/DoCmd.xba
35e961
@@ -2655,7 +2655,7 @@ Private Sub _ShellExecute(sCommand As String)
35e961
 
35e961
 Dim oShell As Object
35e961
 	Set oShell = createUnoService("com.sun.star.system.SystemShellExecute")
35e961
-	oShell.execute(sCommand, "" , com.sun.star.system.SystemShellExecuteFlags.DEFAULTS)
35e961
+	oShell.execute(sCommand, "" , com.sun.star.system.SystemShellExecuteFlags.URIS_ONLY)
35e961
 
35e961
 End Sub				'	_ShellExecute			V0.8.5
35e961
 
35e961
diff --git a/xmloff/source/draw/ximpshap.cxx b/xmloff/source/draw/ximpshap.cxx
35e961
index 2e509f8..ae35f1e 100644
35e961
--- a/xmloff/source/draw/ximpshap.cxx
35e961
+++ b/xmloff/source/draw/ximpshap.cxx
35e961
@@ -87,6 +87,7 @@
35e961
 #include <basegfx/polygon/b2dpolypolygon.hxx>
35e961
 #include <basegfx/polygon/b2dpolypolygontools.hxx>
35e961
 #include <basegfx/vector/b2dvector.hxx>
35e961
+#include <tools/urlobj.hxx>
35e961
 #include <o3tl/safeint.hxx>
35e961
 
35e961
 using namespace ::com::sun::star;
35e961
@@ -3243,6 +3244,9 @@ void SdXMLFloatingFrameShapeContext::StartElement( const css::uno::Reference< cs
35e961
 
35e961
             if( !maHref.isEmpty() )
35e961
             {
35e961
+                if (INetURLObject(maHref).GetProtocol() == INetProtocol::Macro)
35e961
+                    GetImport().NotifyMacroEventRead();
35e961
+
35e961
                 xProps->setPropertyValue("FrameURL", Any(maHref) );
35e961
             }
35e961
         }
35e961
-- 
35e961
2.37.3
35e961