Skip to content

Commit

Permalink
Check i2d_X509_NAME return in X509_NAME_hash_ex/old
Browse files Browse the repository at this point in the history
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #21697)

(cherry picked from commit 945fde5)
  • Loading branch information
3lswear authored and t8m committed Aug 16, 2023
1 parent dd8243b commit 1958d26
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions crypto/x509/x509_cmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,13 @@ unsigned long X509_NAME_hash_ex(const X509_NAME *x, OSSL_LIB_CTX *libctx,
unsigned long ret = 0;
unsigned char md[SHA_DIGEST_LENGTH];
EVP_MD *sha1 = EVP_MD_fetch(libctx, "SHA1", propq);
int i2d_ret;

/* Make sure X509_NAME structure contains valid cached encoding */
i2d_X509_NAME(x, NULL);
i2d_ret = i2d_X509_NAME(x, NULL);
if (ok != NULL)
*ok = 0;
if (sha1 != NULL
if (i2d_ret >= 0 && sha1 != NULL
&& EVP_Digest(x->canon_enc, x->canon_enclen, md, NULL, sha1, NULL)) {
ret = (((unsigned long)md[0]) | ((unsigned long)md[1] << 8L) |
((unsigned long)md[2] << 16L) | ((unsigned long)md[3] << 24L)
Expand Down Expand Up @@ -325,7 +326,9 @@ unsigned long X509_NAME_hash_old(const X509_NAME *x)
goto end;

/* Make sure X509_NAME structure contains valid cached encoding */
i2d_X509_NAME(x, NULL);
if (i2d_X509_NAME(x, NULL) < 0)
goto end;

if (EVP_DigestInit_ex(md_ctx, md5, NULL)
&& EVP_DigestUpdate(md_ctx, x->bytes->data, x->bytes->length)
&& EVP_DigestFinal_ex(md_ctx, md, NULL))
Expand Down

0 comments on commit 1958d26

Please sign in to comment.