Browse Source

Fix memleaks in KDF implementations

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9662)
master
Richard Levitte 3 years ago
committed by Pauli
parent
commit
df2f8af4cb
7 changed files with 9 additions and 11 deletions
  1. +1
    -1
      providers/common/kdfs/hkdf.c
  2. +1
    -1
      providers/common/kdfs/pbkdf2.c
  3. +2
    -3
      providers/common/kdfs/sskdf.c
  4. +2
    -2
      providers/common/kdfs/tls1_prf.c
  5. +1
    -2
      providers/default/kdfs/scrypt.c
  6. +1
    -1
      providers/default/kdfs/sshkdf.c
  7. +1
    -1
      providers/default/kdfs/x942kdf.c

+ 1
- 1
providers/common/kdfs/hkdf.c View File

@ -75,7 +75,6 @@ static void kdf_hkdf_free(void *vctx)
KDF_HKDF *ctx = (KDF_HKDF *)vctx;
kdf_hkdf_reset(ctx);
EVP_MD_meth_free(ctx->md);
OPENSSL_free(ctx);
}
@ -83,6 +82,7 @@ static void kdf_hkdf_reset(void *vctx)
{
KDF_HKDF *ctx = (KDF_HKDF *)vctx;
EVP_MD_meth_free(ctx->md);
OPENSSL_free(ctx->salt);
OPENSSL_clear_free(ctx->key, ctx->key_len);
OPENSSL_cleanse(ctx->info, ctx->info_len);


+ 1
- 1
providers/common/kdfs/pbkdf2.c View File

@ -80,7 +80,6 @@ static void kdf_pbkdf2_free(void *vctx)
KDF_PBKDF2 *ctx = (KDF_PBKDF2 *)vctx;
kdf_pbkdf2_reset(ctx);
EVP_MD_meth_free(ctx->md);
OPENSSL_free(ctx);
}
@ -88,6 +87,7 @@ static void kdf_pbkdf2_reset(void *vctx)
{
KDF_PBKDF2 *ctx = (KDF_PBKDF2 *)vctx;
EVP_MD_meth_free(ctx->md);
OPENSSL_free(ctx->salt);
OPENSSL_clear_free(ctx->pass, ctx->pass_len);
memset(ctx, 0, sizeof(*ctx));


+ 2
- 3
providers/common/kdfs/sskdf.c View File

@ -315,10 +315,11 @@ static void sskdf_reset(void *vctx)
{
KDF_SSKDF *ctx = (KDF_SSKDF *)vctx;
EVP_MD_meth_free(ctx->md);
EVP_MAC_free(ctx->mac);
OPENSSL_clear_free(ctx->secret, ctx->secret_len);
OPENSSL_clear_free(ctx->info, ctx->info_len);
OPENSSL_clear_free(ctx->salt, ctx->salt_len);
EVP_MAC_free(ctx->mac);
memset(ctx, 0, sizeof(*ctx));
}
@ -327,8 +328,6 @@ static void sskdf_free(void *vctx)
KDF_SSKDF *ctx = (KDF_SSKDF *)vctx;
sskdf_reset(ctx);
EVP_MD_meth_free(ctx->md);
EVP_MAC_free(ctx->mac);
OPENSSL_free(ctx);
}


+ 2
- 2
providers/common/kdfs/tls1_prf.c View File

@ -104,8 +104,6 @@ static void kdf_tls1_prf_free(void *vctx)
TLS1_PRF *ctx = (TLS1_PRF *)vctx;
kdf_tls1_prf_reset(ctx);
EVP_MD_meth_free(ctx->sha1);
EVP_MD_meth_free(ctx->md);
OPENSSL_free(ctx);
}
@ -113,6 +111,8 @@ static void kdf_tls1_prf_reset(void *vctx)
{
TLS1_PRF *ctx = (TLS1_PRF *)vctx;
EVP_MD_meth_free(ctx->sha1);
EVP_MD_meth_free(ctx->md);
OPENSSL_clear_free(ctx->sec, ctx->seclen);
OPENSSL_cleanse(ctx->seed, ctx->seedlen);
memset(ctx, 0, sizeof(*ctx));


+ 1
- 2
providers/default/kdfs/scrypt.c View File

@ -74,8 +74,8 @@ static void kdf_scrypt_free(void *vctx)
{
KDF_SCRYPT *ctx = (KDF_SCRYPT *)vctx;
kdf_scrypt_reset(ctx);
EVP_MD_meth_free(ctx->sha256);
kdf_scrypt_reset(ctx);
OPENSSL_free(ctx);
}
@ -85,7 +85,6 @@ static void kdf_scrypt_reset(void *vctx)
OPENSSL_free(ctx->salt);
OPENSSL_clear_free(ctx->pass, ctx->pass_len);
memset(ctx, 0, sizeof(*ctx));
kdf_scrypt_init(ctx);
}


+ 1
- 1
providers/default/kdfs/sshkdf.c View File

@ -63,7 +63,6 @@ static void kdf_sshkdf_free(void *vctx)
KDF_SSHKDF *ctx = (KDF_SSHKDF *)vctx;
kdf_sshkdf_reset(ctx);
EVP_MD_meth_free(ctx->md);
OPENSSL_free(ctx);
}
@ -71,6 +70,7 @@ static void kdf_sshkdf_reset(void *vctx)
{
KDF_SSHKDF *ctx = (KDF_SSHKDF *)vctx;
EVP_MD_meth_free(ctx->md);
OPENSSL_clear_free(ctx->key, ctx->key_len);
OPENSSL_clear_free(ctx->xcghash, ctx->xcghash_len);
OPENSSL_clear_free(ctx->session_id, ctx->session_id_len);


+ 1
- 1
providers/default/kdfs/x942kdf.c View File

@ -255,6 +255,7 @@ static void x942kdf_reset(void *vctx)
{
KDF_X942 *ctx = (KDF_X942 *)vctx;
EVP_MD_meth_free(ctx->md);
OPENSSL_clear_free(ctx->secret, ctx->secret_len);
OPENSSL_clear_free(ctx->ukm, ctx->ukm_len);
memset(ctx, 0, sizeof(*ctx));
@ -265,7 +266,6 @@ static void x942kdf_free(void *vctx)
KDF_X942 *ctx = (KDF_X942 *)vctx;
x942kdf_reset(ctx);
EVP_MD_meth_free(ctx->md);
OPENSSL_free(ctx);
}


Loading…
Cancel
Save