diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-09-13 11:29:37 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-09-15 06:08:27 +0200 |
commit | 96bd77de5ad7b7a13f7e48e0f95c05ef49255aa0 (patch) | |
tree | 4c79c57712124a8589c9e6579b6ec7fec9200c3b /package/source/zippackage | |
parent | 3f65724ec5fc92d5a0078a99932358ef7091435c (diff) |
Use <comphelper/servicehelper.hxx> implementing XUnoTunnel part 5
- Revise uses of getSomething to use getFromUnoTunnel
Where that is impossible, use getSomething_cast to unify casting,
and minimize number of places doing low-level transformations.
The change keeps the existing tunnel references that last for the
duration of the pointers' life, because sometimes destroying such
reference may destroy the pointed object, and result in use after
free.
Change-Id: I291c33223582c34cd2c763aa8aacf0ae899ca4c0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122101
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'package/source/zippackage')
-rw-r--r-- | package/source/zippackage/ZipPackage.cxx | 15 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackageEntry.cxx | 8 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackageFolder.cxx | 17 |
3 files changed, 12 insertions, 28 deletions
diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx index 491a942e206c..d70c2bae27a4 100644 --- a/package/source/zippackage/ZipPackage.cxx +++ b/package/source/zippackage/ZipPackage.cxx @@ -205,8 +205,6 @@ void ZipPackage::parseManifest() static const OUStringLiteral sKeyInfo (u"KeyInfo"); const uno::Sequence < uno::Sequence < PropertyValue > > aManifestSequence = xReader->readManifestSequence ( xSink->getInputStream() ); - ZipPackageStream *pStream = nullptr; - ZipPackageFolder *pFolder = nullptr; const Any *pKeyInfo = nullptr; for ( const uno::Sequence<PropertyValue>& rSequence : aManifestSequence ) @@ -248,16 +246,13 @@ void ZipPackage::parseManifest() aAny = getByHierarchicalName( sPath ); uno::Reference < XUnoTunnel > xUnoTunnel; aAny >>= xUnoTunnel; - sal_Int64 nTest=0; - if ( (nTest = xUnoTunnel->getSomething( ZipPackageFolder::getUnoTunnelId() )) != 0 ) + if (auto pFolder = comphelper::getFromUnoTunnel<ZipPackageFolder>(xUnoTunnel)) { - pFolder = reinterpret_cast < ZipPackageFolder* > ( nTest ); pFolder->SetMediaType ( sMediaType ); pFolder->SetVersion ( sVersion ); } - else + else if (auto pStream = comphelper::getFromUnoTunnel<ZipPackageStream>(xUnoTunnel)) { - pStream = reinterpret_cast < ZipPackageStream* > ( xUnoTunnel->getSomething( ZipPackageStream::getUnoTunnelId() )); pStream->SetMediaType ( sMediaType ); pStream->SetFromManifest( true ); @@ -357,6 +352,8 @@ void ZipPackage::parseManifest() else m_bHasNonEncryptedEntries = true; } + else + throw ZipIOException(THROW_WHERE "Wrong content"); } } @@ -495,11 +492,9 @@ void ZipPackage::parseContentType() uno::Any aIterAny = getByHierarchicalName( aPath ); uno::Reference < lang::XUnoTunnel > xIterTunnel; aIterAny >>= xIterTunnel; - sal_Int64 nTest = xIterTunnel->getSomething( ZipPackageStream::getUnoTunnelId() ); - if ( nTest != 0 ) + if (auto pStream = comphelper::getFromUnoTunnel<ZipPackageStream>(xIterTunnel)) { // this is a package stream, in OFOPXML format only streams can have mediatype - ZipPackageStream *pStream = reinterpret_cast < ZipPackageStream* > ( nTest ); pStream->SetMediaType( rPair.Second ); } } diff --git a/package/source/zippackage/ZipPackageEntry.cxx b/package/source/zippackage/ZipPackageEntry.cxx index a195596b0672..385981b5c901 100644 --- a/package/source/zippackage/ZipPackageEntry.cxx +++ b/package/source/zippackage/ZipPackageEntry.cxx @@ -26,6 +26,7 @@ #include <ZipPackageFolder.hxx> #include <ZipPackageStream.hxx> +#include <comphelper/servicehelper.hxx> #include <comphelper/storagehelper.hxx> using namespace com::sun::star; @@ -93,13 +94,10 @@ void SAL_CALL ZipPackageEntry::setParent( const uno::Reference< XInterface >& xN { if ( !xNewParent.is() ) throw NoSupportException(THROW_WHERE ); - uno::Reference < XUnoTunnel > xTunnel ( xNewParent, UNO_QUERY ); - sal_Int64 nTest = xTunnel->getSomething ( ZipPackageFolder::getUnoTunnelId () ); - if ( nTest == 0 ) + ZipPackageFolder* pNewParent = comphelper::getFromUnoTunnel<ZipPackageFolder>(xNewParent); + if (!pNewParent) throw NoSupportException(THROW_WHERE ); - ZipPackageFolder *pNewParent = reinterpret_cast < ZipPackageFolder * > ( nTest ); - if ( pNewParent != mpParent ) { if ( mpParent && !msName.isEmpty() && mpParent->hasByName ( msName ) && mbAllowRemoveOnInsert ) diff --git a/package/source/zippackage/ZipPackageFolder.cxx b/package/source/zippackage/ZipPackageFolder.cxx index 4c94a78abed9..5ea4213f95fd 100644 --- a/package/source/zippackage/ZipPackageFolder.cxx +++ b/package/source/zippackage/ZipPackageFolder.cxx @@ -164,19 +164,10 @@ void SAL_CALL ZipPackageFolder::insertByName( const OUString& aName, const uno:: if ( !(aElement >>= xRef) ) throw IllegalArgumentException(THROW_WHERE, uno::Reference< uno::XInterface >(), 0 ); - sal_Int64 nTest; - ZipPackageEntry *pEntry; - if ( ( nTest = xRef->getSomething ( ZipPackageFolder::getUnoTunnelId() ) ) != 0 ) - { - ZipPackageFolder *pFolder = reinterpret_cast < ZipPackageFolder * > ( nTest ); - pEntry = pFolder; - } - else if ( ( nTest = xRef->getSomething ( ZipPackageStream::getUnoTunnelId() ) ) != 0 ) - { - ZipPackageStream *pStream = reinterpret_cast < ZipPackageStream * > ( nTest ); - pEntry = pStream; - } - else + ZipPackageEntry* pEntry = comphelper::getFromUnoTunnel<ZipPackageFolder>(xRef); + if (!pEntry) + pEntry = comphelper::getFromUnoTunnel<ZipPackageStream>(xRef); + if (!pEntry) throw IllegalArgumentException(THROW_WHERE, uno::Reference< uno::XInterface >(), 0 ); if (pEntry->getName() != aName ) |