
Fix memory leak error and correct the function return value error. Signed-off-by: Qi Tao <taoqi10@huawei.com> Signed-off-by: JiangShui Yang <yangjiangshui@h-partners.com> --- src/uadk_prov_aead.c | 10 +++++++--- src/uadk_prov_rsa.c | 18 +++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/uadk_prov_aead.c b/src/uadk_prov_aead.c index 3965f60..59c13b4 100644 --- a/src/uadk_prov_aead.c +++ b/src/uadk_prov_aead.c @@ -572,7 +572,7 @@ static int uadk_prov_do_aes_gcm_first(struct aead_priv_ctx *priv, unsigned char if (inlen > MAX_AAD_LEN) { if (priv->mode != ASYNC_MODE) - return SWITCH_TO_SOFT; + goto soft; fprintf(stderr, "the aad len is out of range, aad len = %zu.\n", inlen); return UADK_AEAD_FAIL; @@ -587,13 +587,17 @@ static int uadk_prov_do_aes_gcm_first(struct aead_priv_ctx *priv, unsigned char } if (!priv->req.assoc_bytes) - return SWITCH_TO_SOFT; + goto soft; ret = uadk_do_aead_sync_inner(priv, out, in, inlen, AEAD_MSG_FIRST); if (unlikely(ret < 0)) - return SWITCH_TO_SOFT; + goto soft; return UADK_AEAD_SUCCESS; + +soft: + fprintf(stderr, "aead failed to update aad, switch to soft.\n"); + return SWITCH_TO_SOFT; } static int uadk_prov_do_aes_gcm_update(struct aead_priv_ctx *priv, unsigned char *out, diff --git a/src/uadk_prov_rsa.c b/src/uadk_prov_rsa.c index 21f01a2..eb651c0 100644 --- a/src/uadk_prov_rsa.c +++ b/src/uadk_prov_rsa.c @@ -1464,6 +1464,12 @@ static void rsa_keygen_param_free(struct rsa_keygen_param **keygen_param, static int rsa_pkey_param_alloc(struct rsa_pubkey_param **pub, struct rsa_prikey_param **pri) { + if (pub) { + *pub = OPENSSL_malloc(sizeof(struct rsa_pubkey_param)); + if (!(*pub)) + return -ENOMEM; + } + if (pri) { *pri = OPENSSL_malloc(sizeof(struct rsa_prikey_param)); if (!(*pri)) { @@ -1473,12 +1479,6 @@ static int rsa_pkey_param_alloc(struct rsa_pubkey_param **pub, } } - if (pub) { - *pub = OPENSSL_malloc(sizeof(struct rsa_pubkey_param)); - if (!(*pub)) - return -ENOMEM; - } - return UADK_E_SUCCESS; } @@ -2479,7 +2479,7 @@ static const OSSL_PARAM *uadk_asym_cipher_rsa_gettable_ctx_params(void *vprsactx void *provctx) { if (!get_default_rsa_asym_cipher().gettable_ctx_params) - return UADK_E_FAIL; + return NULL; return get_default_rsa_asym_cipher().gettable_ctx_params(vprsactx, provctx); } @@ -2496,7 +2496,7 @@ static const OSSL_PARAM *uadk_asym_cipher_rsa_settable_ctx_params(void *vprsactx void *provctx) { if (!get_default_rsa_asym_cipher().settable_ctx_params) - return UADK_E_FAIL; + return NULL; return get_default_rsa_asym_cipher().settable_ctx_params(vprsactx, provctx); } @@ -2768,7 +2768,7 @@ static void *uadk_keymgmt_rsa_dup(const void *keydata_from, int selection) static void *uadk_asym_cipher_rsa_dupctx(void *vprsactx) { if (!get_default_rsa_asym_cipher().dupctx) - return UADK_E_FAIL; + return NULL; return get_default_rsa_asym_cipher().dupctx(vprsactx); } -- 2.33.0