From: Hugo Landau Date: Fri, 11 Mar 2022 14:02:39 +0000 (+0000) Subject: Fix bug in scrypt KDF provider dup method X-Git-Tag: openssl-3.2.0-alpha1~2850 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e04c2c02e8e6b9ec71d93c26c14167ceb2165ce8;p=thirdparty%2Fopenssl.git Fix bug in scrypt KDF provider dup method The scrypt KDF provider's dup method calls kdf_scrypt_new passing a libctx, but a provider context is expected. Since the provider context is passed as void *, this was not caught. Reviewed-by: Matt Caswell Reviewed-by: Paul Dale Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/17873) --- diff --git a/providers/implementations/kdfs/scrypt.c b/providers/implementations/kdfs/scrypt.c index 744f87847b8..c070c7b059d 100644 --- a/providers/implementations/kdfs/scrypt.c +++ b/providers/implementations/kdfs/scrypt.c @@ -56,7 +56,7 @@ typedef struct { static void kdf_scrypt_init(KDF_SCRYPT *ctx); -static void *kdf_scrypt_new(void *provctx) +static void *kdf_scrypt_new_inner(OSSL_LIB_CTX *libctx) { KDF_SCRYPT *ctx; @@ -68,11 +68,16 @@ static void *kdf_scrypt_new(void *provctx) ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE); return NULL; } - ctx->libctx = PROV_LIBCTX_OF(provctx); + ctx->libctx = libctx; kdf_scrypt_init(ctx); return ctx; } +static void *kdf_scrypt_new(void *provctx) +{ + return kdf_scrypt_new_inner(PROV_LIBCTX_OF(provctx)); +} + static void kdf_scrypt_free(void *vctx) { KDF_SCRYPT *ctx = (KDF_SCRYPT *)vctx; @@ -99,7 +104,7 @@ static void *kdf_scrypt_dup(void *vctx) const KDF_SCRYPT *src = (const KDF_SCRYPT *)vctx; KDF_SCRYPT *dest; - dest = kdf_scrypt_new(src->libctx); + dest = kdf_scrypt_new_inner(src->libctx); if (dest != NULL) { if (src->sha256 != NULL && !EVP_MD_up_ref(src->sha256)) goto err;