apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From minf...@apache.org
Subject svn commit: r1751806 - in /apr/apr/trunk: CHANGES crypto/apr_crypto.c crypto/apr_crypto_nss.c
Date Thu, 07 Jul 2016 14:55:35 GMT
Author: minfrin
Date: Thu Jul  7 14:55:34 2016
New Revision: 1751806

URL: http://svn.apache.org/viewvc?rev=1751806&view=rev
Log:
apr_crypto: Don't cache the driver if initialisation fails. This
stops the second and subsequent attempt to use the API from failing
claiming the library is not initialised.

Modified:
    apr/apr/trunk/CHANGES
    apr/apr/trunk/crypto/apr_crypto.c
    apr/apr/trunk/crypto/apr_crypto_nss.c

Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?rev=1751806&r1=1751805&r2=1751806&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES [utf-8] (original)
+++ apr/apr/trunk/CHANGES [utf-8] Thu Jul  7 14:55:34 2016
@@ -1,6 +1,10 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 2.0.0
 
+  *) apr_crypto: Don't cache the driver if initialisation fails. This
+     stops the second and subsequent attempt to use the API from failing
+     claiming the library is not initialised. [Graham Leggett]
+
   *) apr_xml_to_text: Add style APR_XML_X2T_PARSED to maintain a
      consistent namespace prefix. [Jari Urpalainen
      <jari.urpalainen nokia.com>]

Modified: apr/apr/trunk/crypto/apr_crypto.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/crypto/apr_crypto.c?rev=1751806&r1=1751805&r2=1751806&view=diff
==============================================================================
--- apr/apr/trunk/crypto/apr_crypto.c (original)
+++ apr/apr/trunk/crypto/apr_crypto.c Thu Jul  7 14:55:34 2016
@@ -182,12 +182,15 @@ APR_DECLARE(apr_status_t) apr_crypto_get
     apr_snprintf(symname, sizeof(symname), "apr_crypto_%s_driver", name);
     rv = apu_dso_load(&dso, &symbol, modname, symname, pool);
     if (rv == APR_SUCCESS || rv == APR_EINIT) { /* previously loaded?!? */
-        *driver = symbol;
-        name = apr_pstrdup(pool, name);
-        apr_hash_set(drivers, name, APR_HASH_KEY_STRING, *driver);
+        apr_crypto_driver_t *d = symbol;
         rv = APR_SUCCESS;
-        if ((*driver)->init) {
-            rv = (*driver)->init(pool, params, result);
+        if (d->init) {
+            rv = d->init(pool, params, result);
+        }
+        if (APR_SUCCESS == rv) {
+            *driver = symbol;
+            name = apr_pstrdup(pool, name);
+            apr_hash_set(drivers, name, APR_HASH_KEY_STRING, *driver);
         }
     }
     apu_dso_mutex_unlock();

Modified: apr/apr/trunk/crypto/apr_crypto_nss.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/crypto/apr_crypto_nss.c?rev=1751806&r1=1751805&r2=1751806&view=diff
==============================================================================
--- apr/apr/trunk/crypto/apr_crypto_nss.c (original)
+++ apr/apr/trunk/crypto/apr_crypto_nss.c Thu Jul  7 14:55:34 2016
@@ -198,9 +198,6 @@ static apr_status_t crypto_init(apr_pool
         return APR_EREINIT;
     }
 
-    apr_pool_cleanup_register(pool, pool, crypto_shutdown_helper,
-            apr_pool_cleanup_null);
-
     if (keyPrefix || certPrefix || secmod) {
         s = NSS_Initialize(dir, certPrefix, keyPrefix, secmod, flags);
     }
@@ -212,15 +209,19 @@ static apr_status_t crypto_init(apr_pool
     }
     if (s != SECSuccess) {
         if (result) {
+            /* Note: all memory must be owned by the caller, in case we're unloaded */
             apu_err_t *err = apr_pcalloc(pool, sizeof(apu_err_t));
             err->rc = PR_GetError();
-            err->msg = PR_ErrorToName(s);
-            err->reason = "Error during 'nss' initialisation";
+            err->msg = apr_pstrdup(pool, PR_ErrorToName(s));
+            err->reason = apr_pstrdup(pool, "Error during 'nss' initialisation");
             *result = err;
         }
         return APR_ECRYPT;
     }
 
+    apr_pool_cleanup_register(pool, pool, crypto_shutdown_helper,
+            apr_pool_cleanup_null);
+
     return APR_SUCCESS;
 
 }



Mime
View raw message