diff options
author | Matt Caswell <matt@openssl.org> | 2023-05-12 15:52:07 +0100 |
---|---|---|
committer | Pauli <pauli@openssl.org> | 2023-06-05 09:09:23 +1000 |
commit | 50001e0e15d4a96213c2eea7c56f80087afa89fd (patch) | |
tree | c37ed000c3770c0d2b28e4499084efffe9eacf53 /crypto | |
parent | 4c56539cb338f1583289f93379ee254b45b66568 (diff) | |
download | openssl-50001e0e15d4a96213c2eea7c56f80087afa89fd.tar.gz |
Avoid an unneccessary lock if we didn't add anything to the store
Partially fixes #20286
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20952)
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/x509/by_dir.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/crypto/x509/by_dir.c b/crypto/x509/by_dir.c index 3c7f67b5a1..cd1b53740b 100644 --- a/crypto/x509/by_dir.c +++ b/crypto/x509/by_dir.c @@ -352,11 +352,15 @@ static int get_cert_by_subject_ex(X509_LOOKUP *xl, X509_LOOKUP_TYPE type, * Note: quadratic time find here since the objects won't generally be * sorted and sorting the would result in O(n^2 log n) complexity. */ - X509_STORE_lock(xl->store_ctx); - j = sk_X509_OBJECT_find(xl->store_ctx->objs, &stmp); - tmp = sk_X509_OBJECT_value(xl->store_ctx->objs, j); - X509_STORE_unlock(xl->store_ctx); - + if (k > 0) { + X509_STORE_lock(xl->store_ctx); + j = sk_X509_OBJECT_find(xl->store_ctx->objs, &stmp); + tmp = sk_X509_OBJECT_value(xl->store_ctx->objs, j); + X509_STORE_unlock(xl->store_ctx); + } else { + j = -1; + tmp = NULL; + } /* * If a CRL, update the last file suffix added for this. * We don't need to add an entry if k is 0 as this is the initial value. |