diff options
author | Dr. David von Oheimb <David.von.Oheimb@siemens.com> | 2020-12-23 19:33:03 +0100 |
---|---|---|
committer | Dr. David von Oheimb <dev@ddvo.net> | 2021-02-04 07:28:11 +0100 |
commit | d53b437f9992f974c1623e9b9b9bdf053aefbcc3 (patch) | |
tree | 12b15a5d0a6e885be5e9118c5b4542c6234039f0 /crypto/cmp/cmp_ctx.c | |
parent | b91a13f429570512bfee290e8ec50096b0667e45 (diff) |
Allow NULL arg to OPENSSL_sk_{dup,deep_copy} returning empty stack
This simplifies many usages
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14040)
Diffstat (limited to 'crypto/cmp/cmp_ctx.c')
-rw-r--r-- | crypto/cmp/cmp_ctx.c | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/crypto/cmp/cmp_ctx.c b/crypto/cmp/cmp_ctx.c index e1b4e50ea9..ccca282721 100644 --- a/crypto/cmp/cmp_ctx.c +++ b/crypto/cmp/cmp_ctx.c @@ -462,8 +462,6 @@ STACK_OF(X509) *OSSL_CMP_CTX_get1_newChain(const OSSL_CMP_CTX *ctx) ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT); return NULL; } - if (ctx->newChain == NULL) - return sk_X509_new_null(); return X509_chain_up_ref(ctx->newChain); } @@ -477,10 +475,9 @@ int ossl_cmp_ctx_set1_newChain(OSSL_CMP_CTX *ctx, STACK_OF(X509) *newChain) return 0; sk_X509_pop_free(ctx->newChain, X509_free); - ctx->newChain= NULL; - if (newChain == NULL) - return 1; - return (ctx->newChain = X509_chain_up_ref(newChain)) != NULL; + ctx->newChain = NULL; + return newChain == NULL || + (ctx->newChain = X509_chain_up_ref(newChain)) != NULL; } /* Returns the stack of extraCerts received in CertRepMessage, NULL on error */ @@ -490,8 +487,6 @@ STACK_OF(X509) *OSSL_CMP_CTX_get1_extraCertsIn(const OSSL_CMP_CTX *ctx) ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT); return NULL; } - if (ctx->extraCertsIn == NULL) - return sk_X509_new_null(); return X509_chain_up_ref(ctx->extraCertsIn); } @@ -507,9 +502,8 @@ int ossl_cmp_ctx_set1_extraCertsIn(OSSL_CMP_CTX *ctx, sk_X509_pop_free(ctx->extraCertsIn, X509_free); ctx->extraCertsIn = NULL; - if (extraCertsIn == NULL) - return 1; - return (ctx->extraCertsIn = X509_chain_up_ref(extraCertsIn)) != NULL; + return extraCertsIn == NULL + || (ctx->extraCertsIn = X509_chain_up_ref(extraCertsIn)) != NULL; } /* @@ -526,9 +520,8 @@ int OSSL_CMP_CTX_set1_extraCertsOut(OSSL_CMP_CTX *ctx, sk_X509_pop_free(ctx->extraCertsOut, X509_free); ctx->extraCertsOut = NULL; - if (extraCertsOut == NULL) - return 1; - return (ctx->extraCertsOut = X509_chain_up_ref(extraCertsOut)) != NULL; + return extraCertsOut == NULL + || (ctx->extraCertsOut = X509_chain_up_ref(extraCertsOut)) != NULL; } /* @@ -580,8 +573,6 @@ STACK_OF(X509) *OSSL_CMP_CTX_get1_caPubs(const OSSL_CMP_CTX *ctx) ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT); return NULL; } - if (ctx->caPubs == NULL) - return sk_X509_new_null(); return X509_chain_up_ref(ctx->caPubs); } @@ -596,9 +587,7 @@ int ossl_cmp_ctx_set1_caPubs(OSSL_CMP_CTX *ctx, STACK_OF(X509) *caPubs) sk_X509_pop_free(ctx->caPubs, X509_free); ctx->caPubs = NULL; - if (caPubs == NULL) - return 1; - return (ctx->caPubs = X509_chain_up_ref(caPubs)) != NULL; + return caPubs == NULL || (ctx->caPubs = X509_chain_up_ref(caPubs)) != NULL; } #define char_dup OPENSSL_strdup |