Add checks for the EVP_MD_get_size() to avoid integer overflow and then explicitly cast from int to size_t.
Fixes: 6f4b766315 ("PROV: add RSA signature implementation")
Signed-off-by: Jiasheng Jiang <jiasheng@purdue.edu>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Todd Short <todd.short@me.com>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23949)
static size_t rsa_get_md_size(const PROV_RSA_CTX *prsactx)
{
- if (prsactx->md != NULL)
- return EVP_MD_get_size(prsactx->md);
+ int md_size;
+
+ if (prsactx->md != NULL) {
+ md_size = EVP_MD_get_size(prsactx->md);
+ if (md_size <= 0)
+ return 0;
+ return md_size;
+ }
return 0;
}