Add X509_CRL_up_ref function
authorDr. Stephen Henson <steve@openssl.org>
Mon, 31 Aug 2015 19:30:20 +0000 (20:30 +0100)
committerDr. Stephen Henson <steve@openssl.org>
Mon, 31 Aug 2015 22:18:54 +0000 (23:18 +0100)
Reviewed-by: Rich Salz <rsalz@openssl.org>
crypto/cms/cms_lib.c
crypto/pkcs7/pk7_lib.c
crypto/store/str_lib.c
crypto/x509/x509_lu.c
crypto/x509/x509_vfy.c
crypto/x509/x509cset.c
include/openssl/x509.h

index 8525ff8..e698c00 100644 (file)
@@ -517,7 +517,7 @@ int CMS_add1_crl(CMS_ContentInfo *cms, X509_CRL *crl)
     int r;
     r = CMS_add0_crl(cms, crl);
     if (r > 0)
-        CRYPTO_add(&crl->references, 1, CRYPTO_LOCK_X509_CRL);
+        X509_CRL_up_ref(crl);
     return r;
 }
 
@@ -570,7 +570,7 @@ STACK_OF(X509_CRL) *CMS_get1_crls(CMS_ContentInfo *cms)
                 sk_X509_CRL_pop_free(crls, X509_CRL_free);
                 return NULL;
             }
-            CRYPTO_add(&rch->d.crl->references, 1, CRYPTO_LOCK_X509_CRL);
+            X509_CRL_up_ref(rch->d.crl);
         }
     }
     return crls;
index 5d321f8..d834741 100644 (file)
@@ -341,7 +341,7 @@ int PKCS7_add_crl(PKCS7 *p7, X509_CRL *crl)
         return 0;
     }
 
-    CRYPTO_add(&crl->references, 1, CRYPTO_LOCK_X509_CRL);
+    X509_CRL_up_ref(crl);
     if (!sk_X509_CRL_push(*sk, crl)) {
         X509_CRL_free(crl);
         return 0;
index fef7111..585752a 100644 (file)
@@ -821,7 +821,7 @@ X509_CRL *STORE_generate_crl(STORE *s, OPENSSL_ITEM attributes[],
         STOREerr(STORE_F_STORE_GENERATE_CRL, STORE_R_FAILED_GENERATING_CRL);
         return 0;
     }
-    CRYPTO_add(&object->data.crl->references, 1, CRYPTO_LOCK_X509_CRL);
+    X509_CRL_up_ref(object->data.crl);
 #ifdef REF_PRINT
     REF_PRINT("X509_CRL", data);
 #endif
@@ -845,7 +845,7 @@ X509_CRL *STORE_get_crl(STORE *s, OPENSSL_ITEM attributes[],
         STOREerr(STORE_F_STORE_GET_CRL, STORE_R_FAILED_GETTING_KEY);
         return 0;
     }
-    CRYPTO_add(&object->data.crl->references, 1, CRYPTO_LOCK_X509_CRL);
+    X509_CRL_up_ref(object->data.crl);
 #ifdef REF_PRINT
     REF_PRINT("X509_CRL", data);
 #endif
@@ -869,7 +869,7 @@ int STORE_store_crl(STORE *s, X509_CRL *data, OPENSSL_ITEM attributes[],
         return 0;
     }
 
-    CRYPTO_add(&data->references, 1, CRYPTO_LOCK_X509_CRL);
+    X509_CRL_up_ref(data);
 #ifdef REF_PRINT
     REF_PRINT("X509_CRL", data);
 #endif
@@ -950,7 +950,7 @@ X509_CRL *STORE_list_crl_next(STORE *s, void *handle)
         STOREerr(STORE_F_STORE_LIST_CRL_NEXT, STORE_R_FAILED_LISTING_KEYS);
         return 0;
     }
-    CRYPTO_add(&object->data.crl->references, 1, CRYPTO_LOCK_X509_CRL);
+    X509_CRL_up_ref(object->data.crl);
 #ifdef REF_PRINT
     REF_PRINT("X509_CRL", data);
 #endif
index ae46df8..d8ba14c 100644 (file)
@@ -409,7 +409,7 @@ void X509_OBJECT_up_ref_count(X509_OBJECT *a)
         CRYPTO_add(&a->data.x509->references, 1, CRYPTO_LOCK_X509);
         break;
     case X509_LU_CRL:
-        CRYPTO_add(&a->data.crl->references, 1, CRYPTO_LOCK_X509_CRL);
+        X509_CRL_up_ref(a->data.crl);
         break;
     }
 }
@@ -565,7 +565,7 @@ STACK_OF(X509_CRL) *X509_STORE_get1_crls(X509_STORE_CTX *ctx, X509_NAME *nm)
     for (i = 0; i < cnt; i++, idx++) {
         obj = sk_X509_OBJECT_value(ctx->ctx->objs, idx);
         x = obj->data.crl;
-        CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509_CRL);
+        X509_CRL_up_ref(x);
         if (!sk_X509_CRL_push(sk, x)) {
             CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
             X509_CRL_free(x);
index a3077b5..332a8c0 100644 (file)
@@ -1025,7 +1025,7 @@ static int get_crl_sk(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509_CRL **pdcrl,
         *pissuer = best_crl_issuer;
         *pscore = best_score;
         *preasons = best_reasons;
-        CRYPTO_add(&best_crl->references, 1, CRYPTO_LOCK_X509_CRL);
+        X509_CRL_up_ref(best_crl);
         X509_CRL_free(*pdcrl);
         *pdcrl = NULL;
         get_delta_sk(ctx, pdcrl, pscore, best_crl, crls);
@@ -1123,7 +1123,7 @@ static void get_delta_sk(X509_STORE_CTX *ctx, X509_CRL **dcrl, int *pscore,
         if (check_delta_base(delta, base)) {
             if (check_crl_time(ctx, delta, 0))
                 *pscore |= CRL_SCORE_TIME_DELTA;
-            CRYPTO_add(&delta->references, 1, CRYPTO_LOCK_X509_CRL);
+            X509_CRL_up_ref(delta);
             *dcrl = delta;
             return;
         }
index 925ba69..c687324 100644 (file)
@@ -132,6 +132,11 @@ int X509_CRL_sort(X509_CRL *c)
     return 1;
 }
 
+void X509_CRL_up_ref(X509_CRL *crl)
+{
+    CRYPTO_add(&crl->references, 1, CRYPTO_LOCK_X509_CRL);
+}
+
 int X509_REVOKED_set_revocationDate(X509_REVOKED *x, ASN1_TIME *tm)
 {
     ASN1_TIME *in;
index dc96a2b..a77f2ba 100644 (file)
@@ -837,6 +837,7 @@ int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name);
 int X509_CRL_set_lastUpdate(X509_CRL *x, const ASN1_TIME *tm);
 int X509_CRL_set_nextUpdate(X509_CRL *x, const ASN1_TIME *tm);
 int X509_CRL_sort(X509_CRL *crl);
+void X509_CRL_up_ref(X509_CRL *crl);
 
 int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial);
 int X509_REVOKED_set_revocationDate(X509_REVOKED *r, ASN1_TIME *tm);