From: Weili Qian qianweili@huawei.com
When the ctx is copied, if the pointer members in the ctx structure do not re-apply for memory and re-alloc session, the double free error occurs when the memory in the source ctx and copied ctx is released.
Signed-off-by: Weili Qian qianweili@huawei.com --- src/uadk_prov_digest.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/src/uadk_prov_digest.c b/src/uadk_prov_digest.c index 8c539ed..86819cb 100644 --- a/src/uadk_prov_digest.c +++ b/src/uadk_prov_digest.c @@ -698,16 +698,24 @@ static void uadk_prov_freectx(void *dctx)
static void *uadk_prov_dupctx(void *dctx) { - struct digest_priv_ctx *in, *ret; + struct digest_priv_ctx *dst_ctx; + int ret;
if (!dctx) return NULL;
- in = (struct digest_priv_ctx *)dctx; - ret = OPENSSL_malloc(sizeof(struct digest_priv_ctx)); - if (ret) - memcpy(ret, in, sizeof(struct digest_priv_ctx)); - return ret; + dst_ctx = OPENSSL_malloc(sizeof(struct digest_priv_ctx)); + if (!dst_ctx) + return NULL; + + memcpy(dst_ctx, dctx, sizeof(struct digest_priv_ctx)); + ret = uadk_digest_init(dst_ctx); + if (!ret) { + OPENSSL_clear_free(dst_ctx, sizeof(struct digest_priv_ctx)); + return NULL; + } + + return dst_ctx; }
static int uadk_prov_init(void *dctx, const OSSL_PARAM params[])