Skip to content

Commit

Permalink
get_cert_by_subject_ex(): Check result of X509_STORE_lock()
Browse files Browse the repository at this point in the history
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #21515)
  • Loading branch information
atishkov authored and t8m committed Jul 25, 2023
1 parent 8ae4b23 commit bc5d9cc
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions crypto/x509/by_dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ static int get_cert_by_subject_ex(X509_LOOKUP *xl, X509_LOOKUP_TYPE type,
* sorted and sorting the would result in O(n^2 log n) complexity.
*/
if (k > 0) {
X509_STORE_lock(xl->store_ctx);
if (!X509_STORE_lock(xl->store_ctx))
goto finish;
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);
Expand Down Expand Up @@ -420,9 +421,10 @@ static int get_cert_by_subject_ex(X509_LOOKUP *xl, X509_LOOKUP_TYPE type,
finish:
/* If we changed anything, resort the objects for faster lookup */
if (!sk_X509_OBJECT_is_sorted(xl->store_ctx->objs)) {
X509_STORE_lock(xl->store_ctx);
sk_X509_OBJECT_sort(xl->store_ctx->objs);
X509_STORE_unlock(xl->store_ctx);
if (X509_STORE_lock(xl->store_ctx)) {
sk_X509_OBJECT_sort(xl->store_ctx->objs);
X509_STORE_unlock(xl->store_ctx);
}
}

BUF_MEM_free(b);
Expand Down

0 comments on commit bc5d9cc

Please sign in to comment.