Skip to content

Commit

Permalink
ssl/ssl_lib.c: Add the check before cast from int to unsigned
Browse files Browse the repository at this point in the history
Add the check before cast from int to unsigned to avoid integer overflow since EVP_MD_get_size() may return negative numbers.

Fixes: 919ba00 ("DANE support structures, constructructors and accessors")
Signed-off-by: Jiasheng Jiang <jiasheng@purdue.edu>

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
(Merged from #23940)
  • Loading branch information
JiangJias authored and nhorman committed Apr 2, 2024
1 parent de85587 commit 165797c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions ssl/ssl_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ static int dane_tlsa_add(SSL_DANE *dane,
int ilen = (int)dlen;
int i;
int num;
int mdsize;

if (dane->trecs == NULL) {
ERR_raise(ERR_LIB_SSL, SSL_R_DANE_NOT_ENABLED);
Expand Down Expand Up @@ -294,9 +295,12 @@ static int dane_tlsa_add(SSL_DANE *dane,
}
}

if (md != NULL && dlen != (size_t)EVP_MD_get_size(md)) {
ERR_raise(ERR_LIB_SSL, SSL_R_DANE_TLSA_BAD_DIGEST_LENGTH);
return 0;
if (md != NULL) {
mdsize = EVP_MD_get_size(md);
if (mdsize < 0 || dlen != (size_t)mdsize) {
ERR_raise(ERR_LIB_SSL, SSL_R_DANE_TLSA_BAD_DIGEST_LENGTH);
return 0;
}
}
if (!data) {
ERR_raise(ERR_LIB_SSL, SSL_R_DANE_TLSA_NULL_DATA);
Expand Down

0 comments on commit 165797c

Please sign in to comment.