From 65cbf983ca4f69b8954f949c2edaaa48824481b3 Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Mon, 31 Aug 2015 20:30:20 +0100 Subject: [PATCH] Add X509_CRL_up_ref function Reviewed-by: Rich Salz --- crypto/cms/cms_lib.c | 4 ++-- crypto/pkcs7/pk7_lib.c | 2 +- crypto/store/str_lib.c | 8 ++++---- crypto/x509/x509_lu.c | 4 ++-- crypto/x509/x509_vfy.c | 4 ++-- crypto/x509/x509cset.c | 5 +++++ include/openssl/x509.h | 1 + 7 files changed, 17 insertions(+), 11 deletions(-) diff --git a/crypto/cms/cms_lib.c b/crypto/cms/cms_lib.c index 8525ff8cf6..e698c006bf 100644 --- a/crypto/cms/cms_lib.c +++ b/crypto/cms/cms_lib.c @@ -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; diff --git a/crypto/pkcs7/pk7_lib.c b/crypto/pkcs7/pk7_lib.c index 5d321f8836..d8347419f4 100644 --- a/crypto/pkcs7/pk7_lib.c +++ b/crypto/pkcs7/pk7_lib.c @@ -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; diff --git a/crypto/store/str_lib.c b/crypto/store/str_lib.c index fef7111f87..585752add1 100644 --- a/crypto/store/str_lib.c +++ b/crypto/store/str_lib.c @@ -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 diff --git a/crypto/x509/x509_lu.c b/crypto/x509/x509_lu.c index ae46df8449..d8ba14c39a 100644 --- a/crypto/x509/x509_lu.c +++ b/crypto/x509/x509_lu.c @@ -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); diff --git a/crypto/x509/x509_vfy.c b/crypto/x509/x509_vfy.c index a3077b5cbc..332a8c0f6c 100644 --- a/crypto/x509/x509_vfy.c +++ b/crypto/x509/x509_vfy.c @@ -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; } diff --git a/crypto/x509/x509cset.c b/crypto/x509/x509cset.c index 925ba69250..c6873240af 100644 --- a/crypto/x509/x509cset.c +++ b/crypto/x509/x509cset.c @@ -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; diff --git a/include/openssl/x509.h b/include/openssl/x509.h index dc96a2bf99..a77f2ba334 100644 --- a/include/openssl/x509.h +++ b/include/openssl/x509.h @@ -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); -- 2.25.1