[Libreoffice-commits] core.git: xmlsecurity/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Sep 27 10:15:27 UTC 2018


 xmlsecurity/source/xmlsec/nss/xmlsignature_nssimpl.cxx |   25 ++++++++---------
 1 file changed, 13 insertions(+), 12 deletions(-)

New commits:
commit 27a2de0bd3f1cf64b9ad3a84b112968941ce6d8e
Author:     Miklos Vajna <vmiklos at collabora.co.uk>
AuthorDate: Thu Sep 27 08:55:07 2018 +0200
Commit:     Miklos Vajna <vmiklos at collabora.co.uk>
CommitDate: Thu Sep 27 12:15:02 2018 +0200

    xmlsecurity nss: avoid deleting the keys manager manually
    
    Change-Id: I53a88116148db9e1ceac4024781516173c3d4666
    Reviewed-on: https://gerrit.libreoffice.org/61021
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins

diff --git a/xmlsecurity/source/xmlsec/nss/xmlsignature_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/xmlsignature_nssimpl.cxx
index f4b1364f52dd..5eaec91e6ecc 100644
--- a/xmlsecurity/source/xmlsec/nss/xmlsignature_nssimpl.cxx
+++ b/xmlsecurity/source/xmlsec/nss/xmlsignature_nssimpl.cxx
@@ -29,6 +29,7 @@
 
 #include <xmlsec-wrapper.h>
 #include <com/sun/star/xml/crypto/XXMLSignature.hpp>
+#include <memory>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno ;
@@ -44,6 +45,14 @@ using ::com::sun::star::xml::crypto::XXMLSignatureTemplate ;
 using ::com::sun::star::xml::crypto::XXMLSecurityContext ;
 using ::com::sun::star::xml::crypto::XUriBinding ;
 
+namespace std
+{
+template <> struct default_delete<xmlSecKeysMngr>
+{
+    void operator()(xmlSecKeysMngrPtr ptr) { SecurityEnvironment_NssImpl::destroyKeysManager(ptr); }
+};
+}
+
 class XMLSignature_NssImpl
     : public ::cppu::WeakImplHelper<xml::crypto::XXMLSignature, lang::XServiceInfo>
 {
@@ -77,7 +86,6 @@ SAL_CALL XMLSignature_NssImpl::generate(
     const Reference< XSecurityEnvironment >& aEnvironment
 )
 {
-    xmlSecKeysMngrPtr pMngr = nullptr ;
     xmlSecDSigCtxPtr pDsigCtx = nullptr ;
     xmlNodePtr pNode = nullptr ;
 
@@ -126,16 +134,15 @@ SAL_CALL XMLSignature_NssImpl::generate(
 
      setErrorRecorder();
 
-    pMngr = pSecEnv->createKeysManager();
+    std::unique_ptr<xmlSecKeysMngr> pMngr(pSecEnv->createKeysManager());
     if( !pMngr ) {
         throw RuntimeException() ;
     }
 
     //Create Signature context
-    pDsigCtx = xmlSecDSigCtxCreate( pMngr ) ;
+    pDsigCtx = xmlSecDSigCtxCreate(pMngr.get());
     if( pDsigCtx == nullptr )
     {
-        SecurityEnvironment_NssImpl::destroyKeysManager( pMngr );
         //throw XMLSignatureException() ;
         clearErrorRecorder();
         return aTemplate;
@@ -156,7 +163,6 @@ SAL_CALL XMLSignature_NssImpl::generate(
 
 
     xmlSecDSigCtxDestroy( pDsigCtx ) ;
-    SecurityEnvironment_NssImpl::destroyKeysManager( pMngr );
 
     //Unregistered the stream/URI binding
     if( xUriBinding.is() )
@@ -172,7 +178,6 @@ SAL_CALL XMLSignature_NssImpl::validate(
     const Reference< XXMLSignatureTemplate >& aTemplate ,
     const Reference< XXMLSecurityContext >& aSecurityCtx
 ) {
-    xmlSecKeysMngrPtr pMngr = nullptr ;
     xmlSecDSigCtxPtr pDsigCtx = nullptr ;
     xmlNodePtr pNode = nullptr ;
     //sal_Bool valid ;
@@ -224,17 +229,15 @@ SAL_CALL XMLSignature_NssImpl::validate(
         if( pSecEnv == nullptr )
             throw RuntimeException() ;
 
-        pMngr = pSecEnv->createKeysManager();
+        std::unique_ptr<xmlSecKeysMngr> pMngr(pSecEnv->createKeysManager());
         if( !pMngr ) {
             throw RuntimeException() ;
         }
 
         //Create Signature context
-        pDsigCtx = xmlSecDSigCtxCreate( pMngr ) ;
+        pDsigCtx = xmlSecDSigCtxCreate(pMngr.get());
         if( pDsigCtx == nullptr )
         {
-            SecurityEnvironment_NssImpl::destroyKeysManager( pMngr );
-            //throw XMLSignatureException() ;
             clearErrorRecorder();
             return aTemplate;
         }
@@ -263,7 +266,6 @@ SAL_CALL XMLSignature_NssImpl::validate(
         {
             aTemplate->setStatus(css::xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED);
             xmlSecDSigCtxDestroy( pDsigCtx ) ;
-            SecurityEnvironment_NssImpl::destroyKeysManager( pMngr );
             break;
         }
         else
@@ -271,7 +273,6 @@ SAL_CALL XMLSignature_NssImpl::validate(
             aTemplate->setStatus(css::xml::crypto::SecurityOperationStatus_UNKNOWN);
         }
         xmlSecDSigCtxDestroy( pDsigCtx ) ;
-        SecurityEnvironment_NssImpl::destroyKeysManager( pMngr );
     }
 
 


More information about the Libreoffice-commits mailing list