File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -531,22 +531,38 @@ void wc_Pkcs11_Finalize(Pkcs11Dev* dev)
531531static int Pkcs11Slot_FindByTokenName (Pkcs11Dev * dev ,
532532 const char * tokenName , size_t tokenNameSz )
533533{
534+ int ret = -1 ;
534535 CK_RV rv ;
535536 CK_ULONG slotCnt = 0 ;
536537 CK_TOKEN_INFO tinfo ;
537- int slotId = -1 ;
538+ int index = -1 ;
539+ CK_SLOT_ID * slot = NULL ;
540+
538541 rv = dev -> func -> C_GetSlotList (CK_TRUE , NULL , & slotCnt );
539542 if (rv == CKR_OK ) {
540- for (slotId = 0 ; slotId < (int )slotCnt ; slotId ++ ) {
541- rv = dev -> func -> C_GetTokenInfo (slotId , & tinfo );
543+ slot = (CK_SLOT_ID * )XMALLOC (slotCnt * sizeof (* slot ), dev -> heap ,
544+ DYNAMIC_TYPE_TMP_BUFFER );
545+ if (slot == NULL )
546+ goto out ;
547+ rv = dev -> func -> C_GetSlotList (CK_TRUE , slot , & slotCnt );
548+ if (rv != CKR_OK )
549+ goto out ;
550+ for (index = 0 ; index < (int )slotCnt ; index ++ ) {
551+ rv = dev -> func -> C_GetTokenInfo (slot [index ], & tinfo );
542552 PKCS11_RV ("C_GetTokenInfo" , rv );
543553 if (rv == CKR_OK &&
544554 XMEMCMP (tinfo .label , tokenName , tokenNameSz ) == 0 ) {
545- return slotId ;
555+ ret = slot [index ];
556+ break ;
546557 }
547558 }
548559 }
549- return -1 ;
560+
561+ out :
562+ if (slot != NULL ) {
563+ XFREE (slot , dev -> heap , DYNAMIC_TYPE_TMP_BUFFER );
564+ }
565+ return ret ;
550566}
551567
552568/* lookup by slotId or tokenName */
You can’t perform that action at this time.
0 commit comments