From: Weili Qian <qianweili@huawei.com> Add explicit outsize check to ensure the output buffer is large enough before proceeding with RSA encryption operation. Signed-off-by: Weili Qian <qianweili@huawei.com> --- src/uadk_prov_rsa_enc.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/uadk_prov_rsa_enc.c b/src/uadk_prov_rsa_enc.c index 66d9fea..9c32bd7 100644 --- a/src/uadk_prov_rsa_enc.c +++ b/src/uadk_prov_rsa_enc.c @@ -483,16 +483,22 @@ static int uadk_asym_cipher_rsa_encrypt(void *vprsactx, unsigned char *out, goto exe_soft; } + len = uadk_rsa_size(priv->rsa); + if (len == 0) { + UADK_ERR("invalid: rsa key size is 0.\n"); + return UADK_P_FAIL; + } + if (!out) { - len = uadk_rsa_size(priv->rsa); - if (len == 0) { - UADK_ERR("invalid: rsa encrypt size.\n"); - return UADK_P_FAIL; - } *outlen = len; return UADK_P_SUCCESS; } + if (outsize < len) { + UADK_ERR("invalid: outsize %d is too small.\n", outsize); + return UADK_P_FAIL; + } + if (priv->pad_mode == RSA_PKCS1_OAEP_PADDING) ret = uadk_asym_cipher_rsa_oaep_encrypt(priv, out, in, inlen); else -- 2.43.0