comphelper/source/misc/hash.cxx                |   14 +++++++++-----
 onlineupdate/source/update/updater/updater.cxx |   13 ++++++++-----
 oox/source/crypto/CryptTools.cxx               |   12 +++++++++++-
 3 files changed, 28 insertions(+), 11 deletions(-)

New commits:
commit 6053df3ecdf89886a4573a47aac789cacf4df008
Author:     Andras Timar <[email protected]>
AuthorDate: Mon Nov 7 14:29:09 2022 +0100
Commit:     Andras Timar <[email protected]>
CommitDate: Wed Jan 25 12:24:34 2023 +0000

    NSS initialization guard
    
    Change-Id: I61a5886d0d13eaef6a61479e35d52a85937075ed
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142385
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Henry Castro <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146042
    Tested-by: Jenkins
    Reviewed-by: Andras Timar <[email protected]>

diff --git a/comphelper/source/misc/hash.cxx b/comphelper/source/misc/hash.cxx
index 980097e234d0..d537b9eeff72 100644
--- a/comphelper/source/misc/hash.cxx
+++ b/comphelper/source/misc/hash.cxx
@@ -77,11 +77,15 @@ struct HashImpl
     {
 
 #if USE_TLS_NSS
-        auto const e = NSS_NoDB_Init(nullptr);
-        if (e != SECSuccess) {
-            PRErrorCode error = PR_GetError();
-            const char* errorText = PR_ErrorToName(error);
-            throw css::uno::RuntimeException("NSS_NoDB_Init failed with " + 
OUString(errorText, strlen(errorText), RTL_TEXTENCODING_UTF8) + " (" + 
OUString::number(static_cast<int>(error)) + ")");
+        if (!NSS_IsInitialized())
+        {
+            auto const e = NSS_NoDB_Init(nullptr);
+            if (e != SECSuccess)
+            {
+                PRErrorCode error = PR_GetError();
+                const char* errorText = PR_ErrorToName(error);
+                throw css::uno::RuntimeException("NSS_NoDB_Init failed with " 
+ OUString(errorText, strlen(errorText), RTL_TEXTENCODING_UTF8) + " (" + 
OUString::number(static_cast<int>(error)) + ")");
+            }
         }
         mpContext = HASH_Create(getNSSType());
         HASH_Begin(mpContext);
diff --git a/onlineupdate/source/update/updater/updater.cxx 
b/onlineupdate/source/update/updater/updater.cxx
index 54750afb4218..467f0b67cd1f 100644
--- a/onlineupdate/source/update/updater/updater.cxx
+++ b/onlineupdate/source/update/updater/updater.cxx
@@ -2919,12 +2919,15 @@ int NS_main(int argc, NS_tchar **argv)
     // need to initialize NSS at all there.
     // Otherwise, minimize the amount of NSS we depend on by avoiding all the 
NSS
     // databases.
-    if (NSS_NoDB_Init(NULL) != SECSuccess)
+    if (!NSS_IsInitialized())
     {
-        PRErrorCode error = PR_GetError();
-        fprintf(stderr, "Could not initialize NSS: %s (%d)",
-                PR_ErrorToName(error), (int) error);
-        _exit(1);
+        if (NSS_NoDB_Init(NULL) != SECSuccess)
+        {
+            PRErrorCode error = PR_GetError();
+            fprintf(stderr, "Could not initialize NSS: %s (%d)",
+                    PR_ErrorToName(error), (int) error);
+            _exit(1);
+        }
     }
 #endif
 
diff --git a/oox/source/crypto/CryptTools.cxx b/oox/source/crypto/CryptTools.cxx
index ee68a8a50815..e0a4b9d686cc 100644
--- a/oox/source/crypto/CryptTools.cxx
+++ b/oox/source/crypto/CryptTools.cxx
@@ -21,6 +21,7 @@
 
 #if USE_TLS_NSS
 #include <nss.h>
+#include <nspr.h>
 #include <pk11pub.h>
 #endif // USE_TLS_NSS
 
@@ -167,7 +168,16 @@ struct CryptoImpl
         , mWrapKey(nullptr)
     {
         // Initialize NSS, database functions are not needed
-        NSS_NoDB_Init(nullptr);
+        if (!NSS_IsInitialized())
+        {
+            auto const e = NSS_NoDB_Init(nullptr);
+            if (e != SECSuccess)
+            {
+                PRErrorCode error = PR_GetError();
+                const char* errorText = PR_ErrorToName(error);
+                throw css::uno::RuntimeException("NSS_NoDB_Init failed with " 
+ OUString(errorText, strlen(errorText), RTL_TEXTENCODING_UTF8) + " (" + 
OUString::number(static_cast<int>(error)) + ")");
+            }
+        }
     }
 
     ~CryptoImpl()

Reply via email to