From f67d8fcee1a5a854d90ea2c77dbb60f1d1e6d3f4 Mon Sep 17 00:00:00 2001 From: antona Date: Thu, 28 Jul 2005 11:27:31 +0000 Subject: [PATCH] Use double indirection in case libgcrypt clones the key for you hack for closing the des cipher. --- ntfsprogs/decrypt.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ntfsprogs/decrypt.c b/ntfsprogs/decrypt.c index 32f0dcc9..cd74b884 100644 --- a/ntfsprogs/decrypt.c +++ b/ntfsprogs/decrypt.c @@ -473,7 +473,8 @@ static gcry_err_code_t ntfs_desx_setkey(void *context, const u8 *key, * Take a note of the ctx->gcry_cipher_hd since we need to close it at * ntfs_decrypt_data_key_close() time. */ - *(gcry_cipher_hd_t*)(key + ((keylen + 7) & ~7)) = ctx->gcry_cipher_hd; + **(gcry_cipher_hd_t***)(key + ((keylen + 7) & ~7)) = + &ctx->gcry_cipher_hd; return GPG_ERR_NO_ERROR; } @@ -614,9 +615,9 @@ ntfs_decrypt_data_key *ntfs_decrypt_data_key_open(unsigned char *data, key->alg_id = *(u32*)(data + 8); key->key_data = (u8*)key + ((sizeof(*key) + 7) & ~7); memcpy(key->key_data, data + 16, key_size); - key->des_gcry_cipher_hd_ptr = (gcry_cipher_hd_t*)(key->key_data + - ((key_size + 7) & ~7)); - *key->des_gcry_cipher_hd_ptr = NULL; + key->des_gcry_cipher_hd_ptr = NULL; + *(gcry_cipher_hd_t***)(key->key_data + ((key_size + 7) & ~7)) = + &key->des_gcry_cipher_hd_ptr; gcry_control(GCRYCTL_DISABLE_SECMEM, 0); switch (key->alg_id) { case CALG_DESX: @@ -691,7 +692,7 @@ ntfs_decrypt_data_key *ntfs_decrypt_data_key_open(unsigned char *data, void ntfs_decrypt_data_key_close(ntfs_decrypt_data_key *key) { NTFS_DECRYPT_DATA_KEY *dkey = (NTFS_DECRYPT_DATA_KEY*)key; - if (*dkey->des_gcry_cipher_hd_ptr) + if (dkey->des_gcry_cipher_hd_ptr) gcry_cipher_close(*dkey->des_gcry_cipher_hd_ptr); gcry_cipher_close(dkey->gcry_cipher_hd); free(key);