[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-4.2' - vcl/source

Michael Meeks michael.meeks at collabora.com
Mon Sep 15 05:45:48 PDT 2014


 vcl/source/gdi/pdfwriter_impl.cxx |   18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

New commits:
commit e8a398bd165e1b90a69c453e0465e28de08b3cf8
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Fri Sep 12 14:09:34 2014 +0100

    fdo#66701 - don't double destroy the HASH when PDF signing.
    
    Accidentally introduced in d73c039fa it seems.
    
    Change-Id: I846314ebca3a24520492887d4d9027f812cfb32f

diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index 89355ad..8f6a7e9 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -5951,6 +5951,17 @@ char *PDFSigningPKCS7PasswordCallback(PK11SlotInfo * /*slot*/, PRBool /*retry*/,
     return (char *)arg;
 }
 
+namespace {
+    class HashContextScope {
+        HASHContext *mpPtr;
+    public:
+        HashContextScope(HASHContext *pPtr) : mpPtr(pPtr) {}
+        ~HashContextScope() { clear(); }
+        void clear() { if (mpPtr) { HASH_Destroy(mpPtr); } mpPtr = NULL; }
+        HASHContext *get() { return mpPtr; }
+    };
+}
+
 bool PDFWriterImpl::finalizeSignature()
 {
 
@@ -6000,9 +6011,8 @@ bool PDFWriterImpl::finalizeSignature()
     // Prepare buffer and calculate PDF file digest
     CHECK_RETURN( (osl_File_E_None == osl_setFilePos( m_aFile, osl_Pos_Absolut, 0) ) );
 
-    boost::scoped_ptr<HASHContext> hc(HASH_Create(HASH_AlgSHA1));
-
-    if (!hc)
+    HashContextScope hc(HASH_Create(HASH_AlgSHA1));
+    if (!hc.get())
     {
         SAL_WARN("vcl.gdi", "PDF Signing: SHA1 HASH_Create failed!");
         return false;
@@ -6033,7 +6043,7 @@ bool PDFWriterImpl::finalizeSignature()
     unsigned char hash[SHA1_LENGTH];
     digest.data = hash;
     HASH_End(hc.get(), digest.data, &digest.len, SHA1_LENGTH);
-    HASH_Destroy(hc.get());
+    hc.clear();
 
     const char *pass = OUStringToOString( m_aContext.SignPassword, RTL_TEXTENCODING_UTF8 ).getStr();
 


More information about the Libreoffice-commits mailing list