[rs-commit] r427 - /mod_cms_sign/trunk/mod_cms_sign.c

rs-commit at redwax.eu rs-commit at redwax.eu
Thu Aug 12 12:59:48 CEST 2021


Author: dirkx at redwax.eu
Date: Thu Aug 12 12:59:47 2021
New Revision: 427

Log:
Clarify sentinel, simplify code.

Modified:
    mod_cms_sign/trunk/mod_cms_sign.c

Modified: mod_cms_sign/trunk/mod_cms_sign.c
==============================================================================
--- mod_cms_sign/trunk/mod_cms_sign.c	(original)
+++ mod_cms_sign/trunk/mod_cms_sign.c	Thu Aug 12 12:59:47 2021
@@ -105,12 +105,6 @@
     return APR_SUCCESS;
 }
 
-static apr_status_t _ctx_cleanup(void *data)
-{
-    EVP_PKEY_CTX_free((EVP_PKEY_CTX *) data);
-    return APR_SUCCESS;
-}
-
 static void *_create_dir_config(apr_pool_t * p, char *dir)
 {
     sign_config_rec *conf = apr_pcalloc(p, sizeof(sign_config_rec));
@@ -124,6 +118,13 @@
     return conf;
 }
 
+
+static void _merge_sk_X509(STACK_OF(X509) * dst, STACK_OF(X509) * src)
+{
+    for (int i = 0; i < sk_X509_num(src); i++)
+	sk_X509_push(dst, sk_X509_value(src, i));
+}
+
 static void *_merge_dir_config(apr_pool_t * p, void *basev, void *addv)
 {
     sign_config_rec *new = _create_dir_config(p, NULL);
@@ -133,13 +134,8 @@
     new->key = (add->key == 0) ? base->key : add->key;
     new->cert = (add->cert == 0) ? base->cert : add->cert;
 
-    STACK_OF(X509) * base_extra = base->extra_certs;
-    for (int i = 0; i < sk_X509_num(base_extra); i++)
-	sk_X509_push(new->extra_certs, sk_X509_value(base_extra, i));
-
-    STACK_OF(X509) * add_extra = add->extra_certs;
-    for (int i = 0; i < sk_X509_num(add_extra); i++)
-	sk_X509_push(new->extra_certs, sk_X509_value(add_extra, i));
+    _merge_sk_X509(new->extra_certs, base->extra_certs);
+    _merge_sk_X509(new->extra_certs, add->extra_certs);
 
     return new;
 }
@@ -446,11 +442,14 @@
 			      ERR_reason_error_string(ERR_get_error()));
 		return HTTP_INTERNAL_SERVER_ERROR;
 	    }
+            
+	    // ignore anyting after EOS; set the 'in' to NULL to use it as
+            // a sentinel 'that we're done'; that shortcurcuits any further
+            // processing.
 	    BIO_free(state->in);
 	    state->in = NULL;
-	    //ignore anyting after EOS
-
-		length = BIO_get_mem_data(state->out, &data);
+
+	    length = BIO_get_mem_data(state->out, &data);
 	    if (length <= 0) {
 		ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, HANDLER ": no CMS data returned");
 		return HTTP_INTERNAL_SERVER_ERROR;



More information about the rs-commit mailing list