Blame SOURCES/opencryptoki-3.18.0-returning_CKR_BUFFER_TOO_SMALL.patch

e0658c
commit b545050b338e46c29936a2748aab7200e69a5c91
e0658c
Author: Ingo Franzki <ifranzki@linux.ibm.com>
e0658c
Date:   Tue Jul 26 15:11:06 2022 +0200
e0658c
e0658c
    EP11: Fix C_GetMechanismList returning CKR_BUFFER_TOO_SMALL
e0658c
    
e0658c
    For mixed card levels, the size query call and the call to obtain the
e0658c
    list may run on different cards. When the size query call runs on a
e0658c
    card with less mechanisms than the second call, will fail, but it
e0658c
    returns the larger larger number of mechanisms.
e0658c
    
e0658c
    The code already re-allocates the buffer for retrieving the mechanism
e0658c
    list, but does not return the larger number in pulCount. This will
e0658c
    lead to a CKR_BUFFER_TOO_SMALL when the application calls C_GetMechanismList
e0658c
    again to obtain the list of mechanisms, because the applications buffer
e0658c
    is too small.
e0658c
    
e0658c
    Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
e0658c
e0658c
diff --git a/usr/lib/ep11_stdll/ep11_specific.c b/usr/lib/ep11_stdll/ep11_specific.c
e0658c
index 8d796452..1629e664 100644
e0658c
--- a/usr/lib/ep11_stdll/ep11_specific.c
e0658c
+++ b/usr/lib/ep11_stdll/ep11_specific.c
e0658c
@@ -8977,6 +8977,8 @@ CK_RV ep11tok_get_mechanism_list(STDLL_TokData_t * tokdata,
e0658c
                 if (rc != CKR_BUFFER_TOO_SMALL)
e0658c
                     goto out;
e0658c
             }
e0658c
+            /* counter was updated in case of CKR_BUFFER_TOO_SMALL */
e0658c
+            *pulCount = counter;
e0658c
         } while (rc == CKR_BUFFER_TOO_SMALL);
e0658c
 
e0658c
         for (i = 0; i < counter; i++) {