File ocki-3.17-EP11-Fix-C_GetMechanismList-returning-CKR_BUFFER_TOO.patch of Package openCryptoki.25497

From 6c8424a1f9cd0d96f27788c9ecec4f13a3a84b66 Mon Sep 17 00:00:00 2001
From: Ingo Franzki <ifranzki@linux.ibm.com>
Date: Tue, 26 Jul 2022 15:11:06 +0200
Subject: [PATCH] EP11: Fix C_GetMechanismList returning CKR_BUFFER_TOO_SMALL

For mixed card levels, the size query call and the call to obtain the
list may run on different cards. When the size query call runs on a
card with less mechanisms than the second call, will fail, but it
returns the larger larger number of mechanisms.

The code already re-allocates the buffer for retrieving the mechanism
list, but does not return the larger number in pulCount. This will
lead to a CKR_BUFFER_TOO_SMALL when the application calls C_GetMechanismList
again to obtain the list of mechanisms, because the applications buffer
is too small.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
---
 usr/lib/ep11_stdll/ep11_specific.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/usr/lib/ep11_stdll/ep11_specific.c b/usr/lib/ep11_stdll/ep11_specific.c
index 75fd46a5..9c2abe50 100644
--- a/usr/lib/ep11_stdll/ep11_specific.c
+++ b/usr/lib/ep11_stdll/ep11_specific.c
@@ -8797,6 +8797,8 @@ CK_RV ep11tok_get_mechanism_list(STDLL_TokData_t * tokdata,
                 if (rc != CKR_BUFFER_TOO_SMALL)
                     goto out;
             }
+            /* counter was updated in case of CKR_BUFFER_TOO_SMALL */
+            *pulCount = counter;
         } while (rc == CKR_BUFFER_TOO_SMALL);
 
         for (i = 0; i < counter; i++) {
-- 
2.16.2.windows.1

openSUSE Build Service is sponsored by