From 02f45075642b099e578668fadf4e8fd3d7a9c349 Mon Sep 17 00:00:00 2001 From: martin Date: Wed, 16 Jun 2010 13:42:59 +0000 Subject: [PATCH] pkcs11: Patch from Andre Zepezauer to remove max_virtual_slots allocation. See http://www.opensc-project.org/pipermail/opensc-devel/2010-June/014356.html git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4417 c6295689-39f2-0310-b995-f0e70906c6a9 --- src/pkcs11/pkcs11-global.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/pkcs11/pkcs11-global.c b/src/pkcs11/pkcs11-global.c index 2fd5a140..ec150c65 100644 --- a/src/pkcs11/pkcs11-global.c +++ b/src/pkcs11/pkcs11-global.c @@ -377,16 +377,8 @@ CK_RV C_GetSlotList(CK_BBOOL tokenPresent, /* only slots with token prese goto out; } - if ( - (found = (CK_SLOT_ID_PTR)malloc ( - sizeof (*found) * sc_pkcs11_conf.max_virtual_slots - )) == NULL - ) { - rv = CKR_HOST_MEMORY; - goto out; - } - - sc_debug(context, SC_LOG_DEBUG_NORMAL, "C_GetSlotList(token=%d, %s)", tokenPresent, (pSlotList==NULL_PTR && sc_pkcs11_conf.plug_and_play)? "plug-n-play":"refresh"); + sc_debug(context, SC_LOG_DEBUG_NORMAL, "C_GetSlotList(token=%d, %s)", tokenPresent, + (pSlotList==NULL_PTR && sc_pkcs11_conf.plug_and_play)? "plug-n-play":"refresh"); /* Slot list can only change in v2.20 */ if (pSlotList == NULL_PTR && sc_pkcs11_conf.plug_and_play) { @@ -394,12 +386,19 @@ CK_RV C_GetSlotList(CK_BBOOL tokenPresent, /* only slots with token prese sc_pkcs11_slot_t *hotplug_slot = list_get_at(&virtual_slots, 0); hotplug_slot->id--; sc_ctx_detect_readers(context); - } + card_detect_all(); + found = (CK_SLOT_ID_PTR) malloc(list_size(&virtual_slots) * sizeof(CK_SLOT_ID)); + + if (found == NULL) { + rv = CKR_HOST_MEMORY; + goto out; + } + numMatches = 0; - for (i=0; islot_info.flags & CKF_TOKEN_PRESENT)) found[numMatches++] = slot->id;