summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-10-28 14:44:34 -0400
committerAshod Nakashian <ashnakash@gmail.com>2019-12-26 03:43:07 +0100
commit7f004baf5ef503b5341e12bc7fc04c6fee3e2acb (patch)
tree13779dd082ab01dfc3e4058f5be7d6a3e4d55ccb
parent391db9909b9456042492b3fdc73eff140d724adf (diff)
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@gmail.com> (cherry picked from commit f29f873d8e638d566f53f9ac5712e49910ee4094) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/85803 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
-rw-r--r--sw/inc/rdfhelper.hxx6
-rw-r--r--sw/source/core/doc/rdfhelper.cxx50
2 files changed, 43 insertions, 13 deletions
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;
}
@@ -37,6 +38,11 @@ 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);
/// Gets all (XResource, key, value) statements in RDF graphs given the graph-names.
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())
{