sw/inc/rdfhelper.hxx | 6 ++++ sw/source/core/doc/rdfhelper.cxx | 50 ++++++++++++++++++++++++++++----------- 2 files changed, 43 insertions(+), 13 deletions(-)
New commits: commit 1c17aa5056afc30c40bd307798180c8c7cf73c12 Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> AuthorDate: Sun Oct 28 14:44:34 2018 -0400 Commit: Ashod Nakashian <ashnak...@gmail.com> CommitDate: Mon Dec 3 08:11:41 2018 +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 <ashnak...@gmail.com> diff --git a/sw/inc/rdfhelper.hxx b/sw/inc/rdfhelper.hxx index 218b81b0708c..4c351d8467f0 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()) { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits