pkcs11: move the slot list size check to slot creation.

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4419 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
martin 2010-06-16 13:43:10 +00:00
parent bfe5b4a965
commit ea7a0ac9a1
2 changed files with 6 additions and 4 deletions

View File

@ -398,7 +398,7 @@ CK_RV C_GetSlotList(CK_BBOOL tokenPresent, /* only slots with token prese
}
numMatches = 0;
for (i=0; i<list_size(&virtual_slots) && i<sc_pkcs11_conf.max_virtual_slots; i++) {
for (i=0; i<list_size(&virtual_slots); i++) {
slot = (sc_pkcs11_slot_t *) list_get_at(&virtual_slots, i);
if (!tokenPresent || (slot->slot_info.flags & CKF_TOKEN_PRESENT))
found[numMatches++] = slot->id;
@ -653,8 +653,7 @@ again:
r = sc_wait_for_event(context, mask, &found, &events, -1, &reader_states);
if (sc_pkcs11_conf.plug_and_play && events & SC_EVENT_READER_ATTACHED) {
/* NSS/Firefox Triggers a C_GetSlotList(NULL) only if a slot ID is returned that it does not know yet
Change the first hotplug slot id on every call to make this happen.
*/
Change the first hotplug slot id on every call to make this happen. */
sc_pkcs11_slot_t *hotplug_slot = list_get_at(&virtual_slots, 0);
*pSlot= hotplug_slot->id -1;

View File

@ -77,10 +77,13 @@ CK_RV create_slot(sc_reader_t *reader)
{
struct sc_pkcs11_slot *slot;
if (list_size(&virtual_slots) >= sc_pkcs11_conf.max_virtual_slots)
return CKR_FUNCTION_FAILED;
slot = (struct sc_pkcs11_slot *)calloc(1, sizeof(struct sc_pkcs11_slot));
if (!slot)
return CKR_HOST_MEMORY;
list_append(&virtual_slots, slot);
slot->login_user = -1;
slot->id = (CK_SLOT_ID) list_locate(&virtual_slots, slot);