uadk_engine/0007-sm2-add-ctx-allocation-check.patch
JangShui Yang 9dd90cee97 Backport uadk engine patch
(cherry picked from commit 793613e405197982521d4079047f8ea5468483bc)
2024-04-07 18:59:10 +08:00

36 lines
1001 B
Diff

From 75ee064d69f687aa43cff40ce2061db1afe75f85 Mon Sep 17 00:00:00 2001
From: Zhiqi Song <songzhiqi1@huawei.com>
Date: Fri, 29 Mar 2024 10:13:25 +0800
Subject: [PATCH 7/7] sm2: add ctx allocation check
Add result check of EVP_MD_CTX_new().
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
Signed-off-by: JiangShui Yang <yangjiangshui@h-partners.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) {
--
2.25.1