Skip to content

Commit 7d83685

Browse files
Correctly use C_GetSlotList() git PKCS#11 2.40
Use a double call to C_GetSlotList() so that the module list is correctly initialized. Fix "trouble using PyKCS11 with libbeidpkcs11 #73" #73
1 parent faf137e commit 7d83685

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

src/pkcs11lib.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,19 @@ CK_RV CPKCS11Lib::C_GetSlotList(
134134

135135
CK_ULONG i;
136136
slotList.clear();
137-
CK_SLOT_ID ck_slotList[1024];
138-
CK_ULONG ulSlotCount = sizeof(ck_slotList)/sizeof(ck_slotList[0]);
139-
rv = m_pFunc->C_GetSlotList(tokenPresent, ck_slotList, &ulSlotCount);
137+
CK_ULONG ulSlotCount;
138+
rv = m_pFunc->C_GetSlotList(tokenPresent, NULL, &ulSlotCount);
140139
if (CKR_OK == rv)
141-
for(i=0; i<ulSlotCount; i++)
142-
slotList.push_back(ck_slotList[i]);
140+
{
141+
CK_SLOT_ID_PTR ck_slotList;
142+
ck_slotList = (CK_SLOT_ID_PTR)malloc(ulSlotCount * sizeof(CK_SLOT_ID));
143+
rv = m_pFunc->C_GetSlotList(tokenPresent, ck_slotList, &ulSlotCount);
144+
if (CKR_OK == rv)
145+
for(i=0; i<ulSlotCount; i++)
146+
slotList.push_back(ck_slotList[i]);
147+
148+
free(ck_slotList);
149+
}
143150

144151
CPKCS11LIB_EPILOGUE;
145152
return rv;

0 commit comments

Comments
 (0)