提交 3e0076c2 编写于 作者: M Matt Caswell

Check md_size isn't negative before we use it

Issue found by Coverity
Reviewed-by: NAndy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6592)
上级 c9d6fdd6
...@@ -25,16 +25,17 @@ static BIGNUM *sm2_compute_msg_hash(const EVP_MD *digest, ...@@ -25,16 +25,17 @@ static BIGNUM *sm2_compute_msg_hash(const EVP_MD *digest,
{ {
EVP_MD_CTX *hash = EVP_MD_CTX_new(); EVP_MD_CTX *hash = EVP_MD_CTX_new();
const int md_size = EVP_MD_size(digest); const int md_size = EVP_MD_size(digest);
uint8_t *za = OPENSSL_zalloc(md_size); uint8_t *za = NULL;
BIGNUM *e = NULL; BIGNUM *e = NULL;
if (hash == NULL || za == NULL) { if (md_size < 0) {
SM2err(SM2_F_SM2_COMPUTE_MSG_HASH, ERR_R_MALLOC_FAILURE); SM2err(SM2_F_SM2_COMPUTE_MSG_HASH, SM2_R_INVALID_DIGEST);
goto done; goto done;
} }
if (md_size < 0) { za = OPENSSL_zalloc(md_size);
SM2err(SM2_F_SM2_COMPUTE_MSG_HASH, SM2_R_INVALID_DIGEST); if (hash == NULL || za == NULL) {
SM2err(SM2_F_SM2_COMPUTE_MSG_HASH, ERR_R_MALLOC_FAILURE);
goto done; goto done;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册