[PATCH 1/2] bcrypt: Fix array index in BCryptEnumAlgorithms().
Hans Leidekker
hans at codeweavers.com
Wed Apr 6 03:38:38 CDT 2022
Signed-off-by: Hans Leidekker <hans at codeweavers.com>
---
dlls/bcrypt/bcrypt_main.c | 11 ++++++-----
dlls/bcrypt/tests/bcrypt.c | 12 +++++++++++-
2 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/dlls/bcrypt/bcrypt_main.c b/dlls/bcrypt/bcrypt_main.c
index 2ffeff66d7b..98ae8c97e3a 100644
--- a/dlls/bcrypt/bcrypt_main.c
+++ b/dlls/bcrypt/bcrypt_main.c
@@ -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;
diff --git a/dlls/bcrypt/tests/bcrypt.c b/dlls/bcrypt/tests/bcrypt.c
index df650379cfb..08ce360cac0 100644
--- a/dlls/bcrypt/tests/bcrypt.c
+++ b/dlls/bcrypt/tests/bcrypt.c
@@ -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)
--
2.30.2
More information about the wine-devel
mailing list