pkcs11-global: Obey to the tokenPresent parameter on C_GetSlotList

Since commit dba0f56 the tokenPresent parameter is ignored in case the
slot has been already seen.

This breaks the API expectations as we may return a slot that has no
token inserted.

So, only consider the SC_PKCS11_SLOT_FLAG_SEEN if tokenPresent is false
This commit is contained in:
Marco Trevisan (Treviño) 2021-03-02 02:22:06 +01:00 committed by Frank Morgner
parent 40e9a9c830
commit 845eac4250
1 changed files with 4 additions and 3 deletions

View File

@ -519,9 +519,10 @@ CK_RV C_GetSlotList(CK_BBOOL tokenPresent, /* only slots with token prese
* - any slot with token;
* - any slot that has already been seen;
*/
if ((!tokenPresent && slot->reader != prev_reader)
|| (slot->slot_info.flags & CKF_TOKEN_PRESENT)
|| (slot->flags & SC_PKCS11_SLOT_FLAG_SEEN)) {
if ((!tokenPresent &&
(slot->reader != prev_reader ||
slot->flags & SC_PKCS11_SLOT_FLAG_SEEN))
|| slot->slot_info.flags & CKF_TOKEN_PRESENT) {
found[numMatches++] = slot->id;
slot->flags |= SC_PKCS11_SLOT_FLAG_SEEN;
}