[rs-commit] r90 - in /redwax-tool/trunk: redwax-tool.h redwax_openssl.c

rs-commit at redwax.eu rs-commit at redwax.eu
Fri Nov 26 17:09:13 CET 2021


Author: minfrin at redwax.eu
Date: Fri Nov 26 17:09:13 2021
New Revision: 90

Log:
Fix pool lifetime mismatches on key index.

Modified:
    redwax-tool/trunk/redwax-tool.h
    redwax-tool/trunk/redwax_openssl.c

Modified: redwax-tool/trunk/redwax-tool.h
==============================================================================
--- redwax-tool/trunk/redwax-tool.h	(original)
+++ redwax-tool/trunk/redwax-tool.h	Fri Nov 26 17:09:13 2021
@@ -217,6 +217,7 @@
     apr_size_t label_len;
     const char *token;
     apr_size_t token_len;
+    apr_hash_t *keys_index;
     void *ctx;
     redwax_key_common_t common;
     union {

Modified: redwax-tool/trunk/redwax_openssl.c
==============================================================================
--- redwax-tool/trunk/redwax_openssl.c	(original)
+++ redwax-tool/trunk/redwax_openssl.c	Fri Nov 26 17:09:13 2021
@@ -829,6 +829,22 @@
     return APR_SUCCESS;
 }
 
+static apr_status_t cleanup_key(void *dummy)
+{
+    if (dummy) {
+
+        redwax_key_t *key = dummy;
+
+        if (key->keys_index) {
+            apr_hash_set(key->keys_index,
+                    key->common.subjectpublickeyinfo_der,
+                    key->common.subjectpublickeyinfo_len, NULL);
+        }
+    }
+
+    return APR_SUCCESS;
+}
+
 static apr_status_t redwax_openssl_initialise(redwax_tool_t *r)
 {
     cert_index = sk_X509_new_null();
@@ -3052,7 +3068,7 @@
             return DECLINED;
         }
 
-        apr_pool_cleanup_register(r->pool, pkey, cleanup_evp_pkey,
+        apr_pool_cleanup_register(key->pool, pkey, cleanup_evp_pkey,
                 apr_pool_cleanup_null);
 
         if (X509_PUBKEY_set(&pub, pkey)) {
@@ -3060,7 +3076,7 @@
             unsigned char *der;
 
             key->common.subjectpublickeyinfo_len = i2d_X509_PUBKEY(pub, NULL);
-            key->common.subjectpublickeyinfo_der = der = apr_palloc(r->pool,
+            key->common.subjectpublickeyinfo_der = der = apr_palloc(key->pool,
                     key->common.subjectpublickeyinfo_len);
             i2d_X509_PUBKEY(pub, &der);
 
@@ -3070,9 +3086,15 @@
                 if (!apr_hash_get(r->keys_index,
                         key->common.subjectpublickeyinfo_der,
                         key->common.subjectpublickeyinfo_len)) {
-                    apr_hash_set(r->keys_index,
+
+                    key->keys_index = r->keys_index;
+
+                    apr_hash_set(key->keys_index,
                             key->common.subjectpublickeyinfo_der,
                             key->common.subjectpublickeyinfo_len, key);
+
+                    apr_pool_cleanup_register(key->pool, key, cleanup_key,
+                            apr_pool_cleanup_null);
                 }
 
             }
@@ -3262,10 +3284,8 @@
 
             unsigned char *der;
 
-            // checkme - r->pool?
-
             key->common.subjectpublickeyinfo_len = i2d_X509_PUBKEY(pub, NULL);
-            key->common.subjectpublickeyinfo_der = der = apr_palloc(r->pool,
+            key->common.subjectpublickeyinfo_der = der = apr_palloc(key->pool,
                     key->common.subjectpublickeyinfo_len);
             i2d_X509_PUBKEY(pub, &der);
 
@@ -3275,9 +3295,15 @@
                 if (!apr_hash_get(r->keys_index,
                         key->common.subjectpublickeyinfo_der,
                         key->common.subjectpublickeyinfo_len)) {
-                    apr_hash_set(r->keys_index,
+
+                    key->keys_index = r->keys_index;
+
+                    apr_hash_set(key->keys_index,
                             key->common.subjectpublickeyinfo_der,
                             key->common.subjectpublickeyinfo_len, key);
+
+                    apr_pool_cleanup_register(key->pool, key, cleanup_key,
+                            apr_pool_cleanup_null);
                 }
 
             }



More information about the rs-commit mailing list