[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - sw/inc sw/source

Ashod Nakashian (via logerrit) logerrit at kemper.freedesktop.org
Thu Dec 26 02:43:37 UTC 2019


 sw/inc/rdfhelper.hxx             |    6 ++++
 sw/source/core/doc/rdfhelper.cxx |   50 ++++++++++++++++++++++++++++-----------
 2 files changed, 43 insertions(+), 13 deletions(-)

New commits:
commit 7f004baf5ef503b5341e12bc7fc04c6fee3e2acb
Author:     Ashod Nakashian <ashod.nakashian at collabora.co.uk>
AuthorDate: Sun Oct 28 14:44:34 2018 -0400
Commit:     Ashod Nakashian <ashnakash at gmail.com>
CommitDate: Thu Dec 26 03:43:07 2019 +0100

    paragraph-sign: exception-safe metadata graph enumeration
    
    Metadata graph enumeration can throw from a number
    functions and break things in horrible ways.
    Here we sanitize against the most egregious offenders,
    but not all possible sources.
    
    Change-Id: I40e006ea433dd7274d4fa08f3e8f8507680ef2f4
    Reviewed-on: https://gerrit.libreoffice.org/63009
    Tested-by: Jenkins
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    (cherry picked from commit f29f873d8e638d566f53f9ac5712e49910ee4094)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/85803
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>

diff --git a/sw/inc/rdfhelper.hxx b/sw/inc/rdfhelper.hxx
index 9ccb39156cb3..b7934678d5f9 100644
--- a/sw/inc/rdfhelper.hxx
+++ b/sw/inc/rdfhelper.hxx
@@ -26,6 +26,7 @@ namespace com { namespace sun { namespace star {
         class XModel;
     }
     namespace rdf {
+        class XDocumentMetadataAccess;
         class XResource;
         class XURI;
     }
@@ -35,6 +36,11 @@ namespace com { namespace sun { namespace star {
 class SW_DLLPUBLIC SwRDFHelper
 {
 public:
+    /// Gets all graph-names in RDF of a given type.
+    static css::uno::Sequence<css::uno::Reference<css::rdf::XURI>>
+    getGraphNames(const css::uno::Reference<css::rdf::XDocumentMetadataAccess>& xDocumentMetadataAccess,
+                  const css::uno::Reference<css::rdf::XURI>& xType);
+
     /// Gets all graph-names in RDF of a given type.
     static css::uno::Sequence<css::uno::Reference<css::rdf::XURI>>
     getGraphNames(const css::uno::Reference<css::frame::XModel>& xModel, const OUString& rType);
diff --git a/sw/source/core/doc/rdfhelper.cxx b/sw/source/core/doc/rdfhelper.cxx
index 29e9e8dcf230..d1fb7d4dbf4f 100644
--- a/sw/source/core/doc/rdfhelper.cxx
+++ b/sw/source/core/doc/rdfhelper.cxx
@@ -23,15 +23,40 @@
 
 using namespace com::sun::star;
 
+css::uno::Sequence<css::uno::Reference<css::rdf::XURI>> SwRDFHelper::getGraphNames(
+    const css::uno::Reference<rdf::XDocumentMetadataAccess>& xDocumentMetadataAccess,
+    const css::uno::Reference<rdf::XURI>& xType)
+{
+    try
+    {
+        return xDocumentMetadataAccess->getMetadataGraphsWithType(xType);
+    }
+    catch (const uno::RuntimeException&)
+    {
+        return uno::Sequence<uno::Reference<rdf::XURI>>();
+    }
+}
+
 css::uno::Sequence<uno::Reference<css::rdf::XURI>>
 SwRDFHelper::getGraphNames(const css::uno::Reference<css::frame::XModel>& xModel,
                            const OUString& rType)
 {
-    uno::Reference<uno::XComponentContext> xComponentContext(
-        comphelper::getProcessComponentContext());
-    uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, rType);
-    uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(xModel, uno::UNO_QUERY);
-    return xDocumentMetadataAccess->getMetadataGraphsWithType(xType);
+    try
+    {
+        uno::Reference<uno::XComponentContext> xComponentContext(
+            comphelper::getProcessComponentContext());
+        // rdf::URI::create may fail with type: com.sun.star.uno.DeploymentException
+        // message: component context fails to supply service com.sun.star.rdf.URI of type com.sun.star.rdf.XURI
+        // context: cppu::ComponentContext
+        uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, rType);
+        uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(xModel,
+                                                                             uno::UNO_QUERY);
+        return getGraphNames(xDocumentMetadataAccess, xType);
+    }
+    catch (const ::css::uno::Exception&)
+    {
+        return uno::Sequence<uno::Reference<rdf::XURI>>();
+    }
 }
 
 std::map<OUString, OUString>
@@ -76,7 +101,7 @@ void SwRDFHelper::addStatement(const css::uno::Reference<css::frame::XModel>& xM
     uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
     uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, rType);
     uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(xModel, uno::UNO_QUERY);
-    uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = xDocumentMetadataAccess->getMetadataGraphsWithType(xType);
+    const uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = getGraphNames(xDocumentMetadataAccess, xType);
     uno::Reference<rdf::XURI> xGraphName;
     if (aGraphNames.hasElements())
         xGraphName = aGraphNames[0];
@@ -96,8 +121,7 @@ bool SwRDFHelper::hasMetadataGraph(const css::uno::Reference<css::frame::XModel>
     uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
     uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, rType);
     uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(xModel, uno::UNO_QUERY);
-    uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = xDocumentMetadataAccess->getMetadataGraphsWithType(xType);
-    return aGraphNames.hasElements();
+    return getGraphNames(xDocumentMetadataAccess, xType).hasElements();
 }
 
 void SwRDFHelper::removeStatement(const css::uno::Reference<css::frame::XModel>& xModel,
@@ -108,7 +132,7 @@ void SwRDFHelper::removeStatement(const css::uno::Reference<css::frame::XModel>&
     uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
     uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, rType);
     uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(xModel, uno::UNO_QUERY);
-    uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = xDocumentMetadataAccess->getMetadataGraphsWithType(xType);
+    const uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = getGraphNames(xDocumentMetadataAccess, xType);
     if (!aGraphNames.hasElements())
         return;
 
@@ -125,7 +149,7 @@ void SwRDFHelper::clearStatements(const css::uno::Reference<css::frame::XModel>&
     uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
     uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, rType);
     uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(xModel, uno::UNO_QUERY);
-    uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = xDocumentMetadataAccess->getMetadataGraphsWithType(xType);
+    const uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = getGraphNames(xDocumentMetadataAccess, xType);
     if (!aGraphNames.hasElements())
         return;
 
@@ -152,7 +176,7 @@ void SwRDFHelper::cloneStatements(const css::uno::Reference<css::frame::XModel>&
     uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
     uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, rType);
     uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(xSrcModel, uno::UNO_QUERY);
-    uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = xDocumentMetadataAccess->getMetadataGraphsWithType(xType);
+    const uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = getGraphNames(xDocumentMetadataAccess, xType);
     if (!aGraphNames.hasElements())
         return;
 
@@ -188,7 +212,7 @@ void SwRDFHelper::removeTextNodeStatement(const OUString& rType, SwTextNode& rTe
     uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
     uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, rType);
     uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(rTextNode.GetDoc()->GetDocShell()->GetBaseModel(), uno::UNO_QUERY);
-    uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = xDocumentMetadataAccess->getMetadataGraphsWithType(xType);
+    const uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = getGraphNames(xDocumentMetadataAccess, xType);
     if (!aGraphNames.hasElements())
         return;
 
@@ -205,7 +229,7 @@ void SwRDFHelper::updateTextNodeStatement(const OUString& rType, const OUString&
     uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
     uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, rType);
     uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(rTextNode.GetDoc()->GetDocShell()->GetBaseModel(), uno::UNO_QUERY);
-    uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = xDocumentMetadataAccess->getMetadataGraphsWithType(xType);
+    const uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = getGraphNames(xDocumentMetadataAccess, xType);
     uno::Reference<rdf::XURI> xGraphName;
     if (aGraphNames.hasElements())
     {


More information about the Libreoffice-commits mailing list