Skip to content

Commit

Permalink
Fix loading more than one certificate in PEM format in X509_load_cert…
Browse files Browse the repository at this point in the history
…_file_ex()

Fixes #22895

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #22885)
  • Loading branch information
olszomal authored and t8m committed Dec 4, 2023
1 parent 7158339 commit 20c680d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crypto/x509/by_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ int X509_load_cert_file_ex(X509_LOOKUP *ctx, const char *file, int type,
count = 0;
goto err;
}
/*
* X509_STORE_add_cert() added a reference rather than a copy,
* so we need a fresh X509 object.
*/
X509_free(x);
x = X509_new_ex(libctx, propq);
if (x == NULL) {
ERR_raise(ERR_LIB_X509, ERR_R_ASN1_LIB);
count = 0;
goto err;
}
count++;
}
} else if (type == X509_FILETYPE_ASN1) {
Expand Down

0 comments on commit 20c680d

Please sign in to comment.