diff options
author | Dr. David von Oheimb <David.von.Oheimb@siemens.com> | 2020-12-23 18:06:05 +0300 |
---|---|---|
committer | Dr. David von Oheimb <dev@ddvo.net> | 2021-02-18 18:50:12 +0300 |
commit | daf1300b80443b6bf0dec19085056ec407925d89 (patch) | |
tree | 037789ed2404c3265d4ae1592266744924b6a980 /crypto/x509/x509_cmp.c | |
parent | 937984efc6ed1664e5aeb0e06067d31520066960 (diff) |
Add internal X509_add_certs_new(), which simplifies matters
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14039)
Diffstat (limited to 'crypto/x509/x509_cmp.c')
-rw-r--r-- | crypto/x509/x509_cmp.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/crypto/x509/x509_cmp.c b/crypto/x509/x509_cmp.c index a74311e92d..9cf02be0cb 100644 --- a/crypto/x509/x509_cmp.c +++ b/crypto/x509/x509_cmp.c @@ -175,14 +175,14 @@ int X509_cmp(const X509 *a, const X509 *b) return rv < 0 ? -1 : rv > 0; } -int X509_add_cert_new(STACK_OF(X509) **sk, X509 *cert, int flags) +int X509_add_cert_new(STACK_OF(X509) **p_sk, X509 *cert, int flags) { - if (*sk == NULL - && (*sk = sk_X509_new_null()) == NULL) { + if (*p_sk == NULL + && (*p_sk = sk_X509_new_null()) == NULL) { ERR_raise(ERR_LIB_X509, ERR_R_MALLOC_FAILURE); return 0; } - return X509_add_cert(*sk, cert, flags); + return X509_add_cert(*p_sk, cert, flags); } int X509_add_cert(STACK_OF(X509) *sk, X509 *cert, int flags) @@ -218,14 +218,25 @@ int X509_add_cert(STACK_OF(X509) *sk, X509 *cert, int flags) int X509_add_certs(STACK_OF(X509) *sk, STACK_OF(X509) *certs, int flags) /* compiler would allow 'const' for the list of certs, yet they are up-ref'ed */ { - int n = sk_X509_num(certs); /* certs may be NULL */ + if (sk == NULL) { + ERR_raise(ERR_LIB_X509, ERR_R_PASSED_NULL_PARAMETER); + return 0; + } + return ossl_x509_add_certs_new(&sk, certs, flags); +} + +int ossl_x509_add_certs_new(STACK_OF(X509) **p_sk, STACK_OF(X509) *certs, + int flags) +/* compiler would allow 'const' for the list of certs, yet they are up-ref'ed */ +{ + int n = sk_X509_num(certs /* may be NULL */); int i; for (i = 0; i < n; i++) { int j = (flags & X509_ADD_FLAG_PREPEND) == 0 ? i : n - 1 - i; /* if prepend, add certs in reverse order to keep original order */ - if (!X509_add_cert(sk, sk_X509_value(certs, j), flags)) + if (!X509_add_cert_new(p_sk, sk_X509_value(certs, j), flags)) return 0; } return 1; |