Commit 57092b35 authored by Ludovic Rousseau's avatar Ludovic Rousseau

MSGRemoveContext(): only release a owned transaction

SCardReleaseContext() shall NOT release a lock (PC/SC transaction)
owned by another context.

Thanks to Frederic Hoerni for the bug report
"[Pcsclite-muscle] closing client cancels ongoing transaction"
http://lists.infradead.org/pipermail/pcsclite-muscle/2018-September/001126.html
parent ea1ecdeb
......@@ -861,7 +861,7 @@ static LONG MSGRemoveContext(SCARDCONTEXT hContext, SCONTEXT * threadContext)
while (list_size(&threadContext->cardsList) != 0)
{
READER_CONTEXT * rContext = NULL;
SCARDHANDLE hCard, hLockId;
SCARDHANDLE hCard;
void *ptr;
/*
......@@ -885,10 +885,7 @@ static LONG MSGRemoveContext(SCARDCONTEXT hContext, SCONTEXT * threadContext)
return rv;
}
hLockId = rContext->hLockId;
rContext->hLockId = 0;
if (hCard != hLockId)
if (hCard != rContext->hLockId)
{
/*
* if the card is locked by someone else we do not reset it
......@@ -898,18 +895,21 @@ static LONG MSGRemoveContext(SCARDCONTEXT hContext, SCONTEXT * threadContext)
}
else
{
/* release the lock */
rContext->hLockId = 0;
/*
* We will use SCardStatus to see if the card has been
* reset there is no need to reset each time
* Disconnect is called
*/
rv = SCardStatus(hCard, NULL, NULL, NULL, NULL, NULL, NULL);
}
if (rv == SCARD_W_RESET_CARD || rv == SCARD_W_REMOVED_CARD)
(void)SCardDisconnect(hCard, SCARD_LEAVE_CARD);
else
(void)SCardDisconnect(hCard, SCARD_RESET_CARD);
if (rv == SCARD_W_RESET_CARD || rv == SCARD_W_REMOVED_CARD)
(void)SCardDisconnect(hCard, SCARD_LEAVE_CARD);
else
(void)SCardDisconnect(hCard, SCARD_RESET_CARD);
}
/* Remove entry from the list */
lrv = list_delete_at(&threadContext->cardsList, 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment