Add result check of EVP_MD_CTX_new().
Signed-off-by: Zhiqi Song songzhiqi1@huawei.com --- src/uadk_sm2.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/uadk_sm2.c b/src/uadk_sm2.c index 8421931..c0a5303 100644 --- a/src/uadk_sm2.c +++ b/src/uadk_sm2.c @@ -152,9 +152,13 @@ static int compute_hash(const char *in, size_t in_len, char *out, size_t out_len, void *usr) { const EVP_MD *digest = (const EVP_MD *)usr; - EVP_MD_CTX *hash = EVP_MD_CTX_new(); + EVP_MD_CTX *hash; int ret = 0;
+ hash = EVP_MD_CTX_new(); + if (!hash) + return -1; + if (EVP_DigestInit(hash, digest) == 0 || EVP_DigestUpdate(hash, in, in_len) == 0 || EVP_DigestFinal(hash, (void *)out, NULL) == 0) {