From: Jiasheng Jiang Date: Fri, 22 Mar 2024 22:12:50 +0000 (+0000) Subject: signature/dsa_sig.c: Add checks for the EVP_MD_get_size() X-Git-Tag: openssl-3.4.0-alpha1~725 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f4174b6db41650363e41af42e82de9cc7ef09a5e;p=thirdparty%2Fopenssl.git signature/dsa_sig.c: Add checks for the EVP_MD_get_size() Add checks for the EVP_MD_get_size() to avoid integer overflow and then explicitly cast from int to size_t. Fixes: 45a845e40b ("Add EVP_DigestSign/EVP_DigestVerify support for DSA") Signed-off-by: Jiasheng Jiang Reviewed-by: Shane Lontis Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/23948) --- diff --git a/providers/implementations/signature/dsa_sig.c b/providers/implementations/signature/dsa_sig.c index b89a0f6836b..12cbdb4356d 100644 --- a/providers/implementations/signature/dsa_sig.c +++ b/providers/implementations/signature/dsa_sig.c @@ -93,8 +93,14 @@ typedef struct { static size_t dsa_get_md_size(const PROV_DSA_CTX *pdsactx) { - if (pdsactx->md != NULL) - return EVP_MD_get_size(pdsactx->md); + int md_size; + + if (pdsactx->md != NULL) { + md_size = EVP_MD_get_size(pdsactx->md); + if (md_size <= 0) + return 0; + return (size_t)md_size; + } return 0; }