Commit 370ffa0d authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

bcrypt: Clear magic bytes on destroy.

Based on a patch by Steven Noonan. Signed-off-by: 's avatarHans Leidekker <hans@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 9e99382b
...@@ -214,6 +214,7 @@ NTSTATUS WINAPI BCryptCloseAlgorithmProvider( BCRYPT_ALG_HANDLE handle, DWORD fl ...@@ -214,6 +214,7 @@ NTSTATUS WINAPI BCryptCloseAlgorithmProvider( BCRYPT_ALG_HANDLE handle, DWORD fl
TRACE( "%p, %08x\n", handle, flags ); TRACE( "%p, %08x\n", handle, flags );
if (!alg || alg->hdr.magic != MAGIC_ALG) return STATUS_INVALID_HANDLE; if (!alg || alg->hdr.magic != MAGIC_ALG) return STATUS_INVALID_HANDLE;
alg->hdr.magic = 0;
heap_free( alg ); heap_free( alg );
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
...@@ -672,7 +673,8 @@ NTSTATUS WINAPI BCryptDestroyHash( BCRYPT_HASH_HANDLE handle ) ...@@ -672,7 +673,8 @@ NTSTATUS WINAPI BCryptDestroyHash( BCRYPT_HASH_HANDLE handle )
TRACE( "%p\n", handle ); TRACE( "%p\n", handle );
if (!hash || hash->hdr.magic != MAGIC_HASH) return STATUS_INVALID_HANDLE; if (!hash || hash->hdr.magic != MAGIC_HASH) return STATUS_INVALID_PARAMETER;
hash->hdr.magic = 0;
heap_free( hash ); heap_free( hash );
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
...@@ -1265,6 +1267,7 @@ NTSTATUS WINAPI BCryptDestroyKey( BCRYPT_KEY_HANDLE handle ) ...@@ -1265,6 +1267,7 @@ NTSTATUS WINAPI BCryptDestroyKey( BCRYPT_KEY_HANDLE handle )
TRACE( "%p\n", handle ); TRACE( "%p\n", handle );
if (!key || key->hdr.magic != MAGIC_KEY) return STATUS_INVALID_HANDLE; if (!key || key->hdr.magic != MAGIC_KEY) return STATUS_INVALID_HANDLE;
key->hdr.magic = 0;
return key_destroy( key ); return key_destroy( key );
} }
......
...@@ -293,6 +293,12 @@ static void test_hash(const struct hash_test *test) ...@@ -293,6 +293,12 @@ static void test_hash(const struct hash_test *test)
ret = pBCryptDestroyHash(hash); ret = pBCryptDestroyHash(hash);
ok(ret == STATUS_SUCCESS, "got %08x\n", ret); ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
ret = pBCryptDestroyHash(hash);
ok(ret == STATUS_INVALID_PARAMETER, "got %08x\n", ret);
ret = pBCryptDestroyHash(NULL);
ok(ret == STATUS_INVALID_PARAMETER, "got %08x\n", ret);
ret = pBCryptCloseAlgorithmProvider(alg, 0); ret = pBCryptCloseAlgorithmProvider(alg, 0);
ok(ret == STATUS_SUCCESS, "got %08x\n", ret); ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
} }
...@@ -1415,8 +1421,17 @@ static void test_BCryptDecrypt(void) ...@@ -1415,8 +1421,17 @@ static void test_BCryptDecrypt(void)
ok(ret == STATUS_INVALID_HANDLE, "got %08x\n", ret); ok(ret == STATUS_INVALID_HANDLE, "got %08x\n", ret);
HeapFree(GetProcessHeap(), 0, buf); HeapFree(GetProcessHeap(), 0, buf);
ret = pBCryptDestroyKey(NULL);
ok(ret == STATUS_INVALID_HANDLE, "got %08x\n", ret);
ret = pBCryptCloseAlgorithmProvider(aes, 0); ret = pBCryptCloseAlgorithmProvider(aes, 0);
ok(ret == STATUS_SUCCESS, "got %08x\n", ret); ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
ret = pBCryptCloseAlgorithmProvider(aes, 0);
ok(ret == STATUS_INVALID_HANDLE, "got %08x\n", ret);
ret = pBCryptCloseAlgorithmProvider(NULL, 0);
ok(ret == STATUS_INVALID_HANDLE, "got %08x\n", ret);
} }
static void test_key_import_export(void) static void test_key_import_export(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment