]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Avoid an unneccessary lock if we didn't add anything to the store
authorMatt Caswell <matt@openssl.org>
Fri, 12 May 2023 14:52:07 +0000 (15:52 +0100)
committerPauli <pauli@openssl.org>
Sun, 4 Jun 2023 23:10:07 +0000 (09:10 +1000)
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)

(cherry picked from commit 50001e0e15d4a96213c2eea7c56f80087afa89fd)

crypto/x509/by_dir.c

index 1bc397a84708d1f809a576c55452026dc864d95b..97e6ea0ee184b01a121c06e92dfa85257afff63c 100644 (file)
@@ -348,11 +348,15 @@ static int get_cert_by_subject_ex(X509_LOOKUP *xl, X509_LOOKUP_TYPE type,
         /*
          * we have added it to the cache so now pull it out again
          */
-        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.