126 lines
3.6 KiB
Diff
126 lines
3.6 KiB
Diff
From 5eaaad42f162a6cc998c9de232a83ed3f609ddae Mon Sep 17 00:00:00 2001
|
|
From: Zhiqi Song <songzhiqi1@huawei.com>
|
|
Date: Sat, 17 Jun 2023 20:42:06 +0800
|
|
Subject: [PATCH 21/48] ecc: Add pkey method null pointer judgment
|
|
|
|
Add pkey method null pointer judgement for function
|
|
get_openssl_pkey_meth(), avoid accessing null pointer
|
|
in abnormal cases.
|
|
|
|
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
|
|
---
|
|
src/uadk_ec.c | 5 +++++
|
|
src/uadk_ecx.c | 8 ++++++++
|
|
src/uadk_sm2.c | 25 +++++++++++++++++++++++++
|
|
3 files changed, 38 insertions(+)
|
|
|
|
diff --git a/src/uadk_ec.c b/src/uadk_ec.c
|
|
index d7ad815..781e7f1 100644
|
|
--- a/src/uadk_ec.c
|
|
+++ b/src/uadk_ec.c
|
|
@@ -1418,6 +1418,11 @@ int uadk_ec_create_pmeth(struct uadk_pkey_meth *pkey_meth)
|
|
}
|
|
|
|
openssl_meth = get_openssl_pkey_meth(EVP_PKEY_EC);
|
|
+ if (!openssl_meth) {
|
|
+ fprintf(stderr, "failed to get ec pkey methods\n");
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
EVP_PKEY_meth_copy(meth, openssl_meth);
|
|
|
|
pkey_meth->ec = meth;
|
|
diff --git a/src/uadk_ecx.c b/src/uadk_ecx.c
|
|
index e45fa5e..aebd808 100644
|
|
--- a/src/uadk_ecx.c
|
|
+++ b/src/uadk_ecx.c
|
|
@@ -811,6 +811,10 @@ int uadk_x25519_create_pmeth(struct uadk_pkey_meth *pkey_meth)
|
|
}
|
|
|
|
openssl_meth = get_openssl_pkey_meth(EVP_PKEY_X25519);
|
|
+ if (!openssl_meth) {
|
|
+ fprintf(stderr, "failed to get x25519 pkey methods\n");
|
|
+ return UADK_E_FAIL;
|
|
+ }
|
|
|
|
EVP_PKEY_meth_copy(meth, openssl_meth);
|
|
|
|
@@ -852,6 +856,10 @@ int uadk_x448_create_pmeth(struct uadk_pkey_meth *pkey_meth)
|
|
}
|
|
|
|
openssl_meth = get_openssl_pkey_meth(EVP_PKEY_X448);
|
|
+ if (!openssl_meth) {
|
|
+ fprintf(stderr, "failed to get x448 pkey methods\n");
|
|
+ return UADK_E_FAIL;
|
|
+ }
|
|
|
|
EVP_PKEY_meth_copy(meth, openssl_meth);
|
|
|
|
diff --git a/src/uadk_sm2.c b/src/uadk_sm2.c
|
|
index 63d4fdf..1f678ed 100644
|
|
--- a/src/uadk_sm2.c
|
|
+++ b/src/uadk_sm2.c
|
|
@@ -279,6 +279,11 @@ static int openssl_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
|
|
PFUNC_SIGN sign_pfunc = NULL;
|
|
|
|
openssl_meth = get_openssl_pkey_meth(EVP_PKEY_SM2);
|
|
+ if (!openssl_meth) {
|
|
+ fprintf(stderr, "failed to get sm2 pkey methods\n");
|
|
+ return -1;
|
|
+ }
|
|
+
|
|
EVP_PKEY_meth_get_sign(openssl_meth, NULL, &sign_pfunc);
|
|
if (!sign_pfunc) {
|
|
fprintf(stderr, "sign_pfunc is NULL\n");
|
|
@@ -296,6 +301,11 @@ static int openssl_verify(EVP_PKEY_CTX *ctx,
|
|
PFUNC_VERIFY verify_pfunc = NULL;
|
|
|
|
openssl_meth = get_openssl_pkey_meth(EVP_PKEY_SM2);
|
|
+ if (!openssl_meth) {
|
|
+ fprintf(stderr, "failed to get sm2 pkey methods\n");
|
|
+ return -1;
|
|
+ }
|
|
+
|
|
EVP_PKEY_meth_get_verify(openssl_meth, NULL, &verify_pfunc);
|
|
if (!verify_pfunc) {
|
|
fprintf(stderr, "verify_pfunc is NULL\n");
|
|
@@ -313,6 +323,11 @@ static int openssl_encrypt(EVP_PKEY_CTX *ctx,
|
|
PFUNC_DEC enc_pfunc = NULL;
|
|
|
|
openssl_meth = get_openssl_pkey_meth(EVP_PKEY_SM2);
|
|
+ if (!openssl_meth) {
|
|
+ fprintf(stderr, "failed to get sm2 pkey methods\n");
|
|
+ return -1;
|
|
+ }
|
|
+
|
|
EVP_PKEY_meth_get_encrypt(openssl_meth, NULL, &enc_pfunc);
|
|
if (!enc_pfunc) {
|
|
fprintf(stderr, "enc_pfunc is NULL\n");
|
|
@@ -330,6 +345,11 @@ static int openssl_decrypt(EVP_PKEY_CTX *ctx,
|
|
PFUNC_ENC dec_pfunc = NULL;
|
|
|
|
openssl_meth = get_openssl_pkey_meth(EVP_PKEY_SM2);
|
|
+ if (!openssl_meth) {
|
|
+ fprintf(stderr, "failed to get sm2 pkey methods\n");
|
|
+ return -1;
|
|
+ }
|
|
+
|
|
EVP_PKEY_meth_get_decrypt(openssl_meth, NULL, &dec_pfunc);
|
|
if (!dec_pfunc) {
|
|
fprintf(stderr, "dec_pfunc is NULL\n");
|
|
@@ -1614,6 +1634,11 @@ int uadk_sm2_create_pmeth(struct uadk_pkey_meth *pkey_meth)
|
|
}
|
|
|
|
openssl_meth = get_openssl_pkey_meth(EVP_PKEY_SM2);
|
|
+ if (!openssl_meth) {
|
|
+ fprintf(stderr, "failed to get sm2 pkey methods\n");
|
|
+ return -1;
|
|
+ }
|
|
+
|
|
EVP_PKEY_meth_copy(meth, openssl_meth);
|
|
|
|
if (!uadk_e_ecc_get_support_state(SM2_SUPPORT)) {
|
|
--
|
|
2.25.1
|
|
|