Blame SOURCES/opencryptoki-50a8a8806059647a3e446fd129995af61ec54867.patch

8d6fe3
commit 50a8a8806059647a3e446fd129995af61ec54867
8d6fe3
Author: Ingo Franzki <ifranzki@linux.ibm.com>
8d6fe3
Date:   Tue Dec 3 14:58:26 2019 +0100
8d6fe3
8d6fe3
    EP11: Fix EC-uncompress buffer length
8d6fe3
    
8d6fe3
    Function ec_uncompress_public_key() expects the size of the output
8d6fe3
    buffer in out_pubkey to be specified in the out_len parameter.
8d6fe3
    However, variable pubkey_len is uninitialized when calling
8d6fe3
    ec_uncompress_public_key(), so this may result in CKR_BUFFER_TOO_SMALL
8d6fe3
    dependent on the value of pubkey_len.
8d6fe3
    Fix this by setting pubkey_len to the size of the public key buffer
8d6fe3
    allocated above.
8d6fe3
    
8d6fe3
    Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
8d6fe3
8d6fe3
diff --git a/usr/lib/ep11_stdll/ep11_specific.c b/usr/lib/ep11_stdll/ep11_specific.c
8d6fe3
index 38b6708f..10dfe4e0 100644
8d6fe3
--- a/usr/lib/ep11_stdll/ep11_specific.c
8d6fe3
+++ b/usr/lib/ep11_stdll/ep11_specific.c
8d6fe3
@@ -2034,9 +2034,10 @@ static CK_RV import_EC_key(STDLL_TokData_t * tokdata, SESSION * sess,
8d6fe3
         rc = get_ecsiglen(ec_key_obj, &privkey_len);
8d6fe3
         if (rc != CKR_OK)
8d6fe3
             goto import_EC_key_end;
8d6fe3
-        privkey_len /= 2; /* Public key is half the size of an EC signature */
8d6fe3
+        privkey_len /= 2; /* private key is half the size of an EC signature */
8d6fe3
 
8d6fe3
-        pubkey = (CK_BYTE *)malloc(1 + 2 * privkey_len);
8d6fe3
+        pubkey_len = 1 + 2 * privkey_len;
8d6fe3
+        pubkey = (CK_BYTE *)malloc(pubkey_len);
8d6fe3
         if (pubkey == NULL) {
8d6fe3
             rc = CKR_HOST_MEMORY;
8d6fe3
             goto import_EC_key_end;