Skip to content

Commit

Permalink
RFUnlockSharing: handle SCARD_SHARE_EXCLUSIVE
Browse files Browse the repository at this point in the history
When a card is connected using SCARD_SHARE_EXCLUSIVE then
RFUnlockSharing() called by SCardEndTransaction() should not be able to
remove the exclusive access.

The bug was detected because the following sequence worked but should
not:
SCardConnect(..., SCARD_SHARE_EXCLUSIVE, ...);
SCardEndTransaction();

An error was reported only on the second SCardEndTransaction() call.

Now the first call to SCardEndTransaction() will fail and the card
connection will stay exclusive.

Thanks to Christophe Ferrando for the bug report in "[Pcsclite-muscle]
SCARD_E_NOT_TRANSACTED"
http://lists.alioth.debian.org/pipermail/pcsclite-muscle/Week-of-Mon-20160516/000598.html
  • Loading branch information
LudovicRousseau committed May 20, 2016
1 parent 88b2085 commit b7a4f8f
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/readerfactory.c
Original file line number Diff line number Diff line change
Expand Up @@ -1027,15 +1027,25 @@ LONG RFUnlockSharing(SCARDHANDLE hCard, READER_CONTEXT * rContext)
rv = RFCheckSharing(hCard, rContext);
if (SCARD_S_SUCCESS == rv)
{
if (rContext->LockCount > 0)
if (PCSCLITE_SHARING_EXCLUSIVE_CONTEXT == rContext->contexts)
{
rContext->LockCount -= 1;
if (0 == rContext->LockCount)
rContext->hLockId = 0;
if (rContext->LockCount > 1)
rContext->LockCount -= 1;
else
rv = SCARD_E_NOT_TRANSACTED;
}
else
/* rContext->LockCount == 0 */
rv = SCARD_E_NOT_TRANSACTED;
{
if (rContext->LockCount > 0)
{
rContext->LockCount -= 1;
if (0 == rContext->LockCount)
rContext->hLockId = 0;
}
else
/* rContext->LockCount == 0 */
rv = SCARD_E_NOT_TRANSACTED;
}
}
(void)pthread_mutex_unlock(&LockMutex);

Expand Down

0 comments on commit b7a4f8f

Please sign in to comment.