From: Pauli Date: Sun, 16 May 2021 23:45:33 +0000 (+1000) Subject: hmac: fix coverity 1484888 negative integer to size_t conversion X-Git-Tag: openssl-3.0.0-alpha17~76 X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=commitdiff_plain;h=678d0dba6cdcae7dd742d4d0d65da101e9ada1d2 hmac: fix coverity 1484888 negative integer to size_t conversion More theoretical than real but easy and cheap to check for. Reviewed-by: Tomas Mraz Reviewed-by: Shane Lontis (Merged from https://github.com/openssl/openssl/pull/15300) --- diff --git a/crypto/hmac/hmac.c b/crypto/hmac/hmac.c index 6d142f2cbb..f800cb8f89 100644 --- a/crypto/hmac/hmac.c +++ b/crypto/hmac/hmac.c @@ -221,10 +221,13 @@ unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len, unsigned char *md, unsigned int *md_len) { static unsigned char static_md[EVP_MAX_MD_SIZE]; + int size = EVP_MD_size(evp_md); + if (size < 0) + return NULL; return EVP_Q_mac(NULL, "HMAC", NULL, EVP_MD_name(evp_md), NULL, key, key_len, data, data_len, - md == NULL ? static_md : md, EVP_MD_size(evp_md), md_len); + md == NULL ? static_md : md, size, md_len); } void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags)