bcrypt: Fix array index in BCryptEnumAlgorithms().

Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hans Leidekker 2022-04-06 10:38:38 +02:00 committed by Alexandre Julliard
parent 807d368f1d
commit 40306db341
2 changed files with 17 additions and 6 deletions

View File

@ -147,7 +147,7 @@ NTSTATUS WINAPI BCryptEnumAlgorithms( ULONG type, ULONG *ret_count, BCRYPT_ALGOR
BCRYPT_SIGNATURE_OPERATION |\
BCRYPT_RNG_OPERATION;
BCRYPT_ALGORITHM_IDENTIFIER *list;
ULONG i, count = 0;
ULONG i, j, count = 0;
TRACE( "%#lx, %p, %p, %#lx\n", type, ret_count, ret_list, flags );
@ -160,12 +160,13 @@ NTSTATUS WINAPI BCryptEnumAlgorithms( ULONG type, ULONG *ret_count, BCRYPT_ALGOR
if (!(list = malloc( count * sizeof(*list) ))) return STATUS_NO_MEMORY;
for (i = 0; i < ARRAY_SIZE( builtin_algorithms ); i++)
for (i = 0, j = 0; i < ARRAY_SIZE( builtin_algorithms ); i++)
{
if (!match_operation_type( type, builtin_algorithms[i].class )) continue;
list[i].pszName = (WCHAR *)builtin_algorithms[i].name;
list[i].dwClass = builtin_algorithms[i].class;
list[i].dwFlags = 0;
list[j].pszName = (WCHAR *)builtin_algorithms[i].name;
list[j].dwClass = builtin_algorithms[i].class;
list[j].dwFlags = 0;
j++;
}
*ret_count = count;

View File

@ -2668,7 +2668,7 @@ static void test_BCryptEnumAlgorithms(void)
{
BCRYPT_ALGORITHM_IDENTIFIER *list;
NTSTATUS ret;
ULONG count;
ULONG count, op;
ret = BCryptEnumAlgorithms(0, NULL, NULL, 0);
ok(ret == STATUS_INVALID_PARAMETER, "got %#lx\n", ret);
@ -2689,6 +2689,16 @@ static void test_BCryptEnumAlgorithms(void)
ok(list != NULL, "NULL list\n");
ok(count, "got %lu\n", count);
BCryptFreeBuffer( list );
op = BCRYPT_CIPHER_OPERATION | BCRYPT_ASYMMETRIC_ENCRYPTION_OPERATION | BCRYPT_SIGNATURE_OPERATION |
BCRYPT_SECRET_AGREEMENT_OPERATION;
count = 0;
list = NULL;
ret = BCryptEnumAlgorithms(op, &count, &list, 0);
ok(!ret, "got %#lx\n", ret);
ok(list != NULL, "NULL list\n");
ok(count, "got %lu\n", count);
BCryptFreeBuffer( list );
}
static void test_aes_vector(void)