[Pcsclite-cvs-commit] r2963 - /trunk/PCSC/src/winscard_clnt.c
rousseau at users.alioth.debian.org
rousseau at users.alioth.debian.org
Fri May 16 09:38:19 UTC 2008
Author: rousseau
Date: Fri May 16 09:38:19 2008
New Revision: 2963
URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=2963
Log:
SCardReconnect(), SCardDisconnect(), SCardBeginTransaction(),
SCardEndTransaction(), SCardCancelTransaction(), SCardStatus(),
SCardControl(), SCardGetSetAttrib(), SCardTransmit(): check that the
card handle is still valid after we (should) hold the lock
The context may have been closed by another thread using
SCardReleaseContext() on the same context
[#300849] problems in multithreading environment (segmentation faults,
SCardCancel does not work)
Modified:
trunk/PCSC/src/winscard_clnt.c
Modified: trunk/PCSC/src/winscard_clnt.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/winscard_clnt.c?rev=2963&op=diff
==============================================================================
--- trunk/PCSC/src/winscard_clnt.c (original)
+++ trunk/PCSC/src/winscard_clnt.c Fri May 16 09:38:19 2008
@@ -915,6 +915,14 @@
SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+ /* check the handle is still valid */
+ rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex);
+ if (rv == -1)
+ /* the handle is now invalid
+ * -> another thread may have called SCardReleaseContext
+ * -> so the mMutex has been unlocked */
+ return SCARD_E_INVALID_HANDLE;
+
for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
{
char *r = psContextMap[dwContextIndex].psChannelMap[dwChannelIndex].readerName;
@@ -1025,6 +1033,14 @@
return SCARD_E_INVALID_HANDLE;
SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+
+ /* check the handle is still valid */
+ rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex);
+ if (rv == -1)
+ /* the handle is now invalid
+ * -> another thread may have called SCardReleaseContext
+ * -> so the mMutex has been unlocked */
+ return SCARD_E_INVALID_HANDLE;
scDisconnectStruct.hCard = hCard;
scDisconnectStruct.dwDisposition = dwDisposition;
@@ -1122,6 +1138,14 @@
return SCARD_E_INVALID_HANDLE;
SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+
+ /* check the handle is still valid */
+ rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex);
+ if (rv == -1)
+ /* the handle is now invalid
+ * -> another thread may have called SCardReleaseContext
+ * -> so the mMutex has been unlocked */
+ return SCARD_E_INVALID_HANDLE;
for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
{
@@ -1252,6 +1276,14 @@
SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+ /* check the handle is still valid */
+ rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex);
+ if (rv == -1)
+ /* the handle is now invalid
+ * -> another thread may have called SCardReleaseContext
+ * -> so the mMutex has been unlocked */
+ return SCARD_E_INVALID_HANDLE;
+
for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
{
char *r = psContextMap[dwContextIndex].psChannelMap[dwChannelIndex].readerName;
@@ -1337,6 +1369,14 @@
return SCARD_E_INVALID_HANDLE;
SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+
+ /* check the handle is still valid */
+ rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex);
+ if (rv == -1)
+ /* the handle is now invalid
+ * -> another thread may have called SCardReleaseContext
+ * -> so the mMutex has been unlocked */
+ return SCARD_E_INVALID_HANDLE;
for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
{
@@ -1495,6 +1535,14 @@
return SCARD_E_INVALID_HANDLE;
SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+
+ /* check the handle is still valid */
+ rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex);
+ if (rv == -1)
+ /* the handle is now invalid
+ * -> another thread may have called SCardReleaseContext
+ * -> so the mMutex has been unlocked */
+ return SCARD_E_INVALID_HANDLE;
r = psContextMap[dwContextIndex].psChannelMap[dwChannelIndex].readerName;
for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
@@ -2279,6 +2327,14 @@
return SCARD_E_INVALID_HANDLE;
SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+
+ /* check the handle is still valid */
+ rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex);
+ if (rv == -1)
+ /* the handle is now invalid
+ * -> another thread may have called SCardReleaseContext
+ * -> so the mMutex has been unlocked */
+ return SCARD_E_INVALID_HANDLE;
for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
{
@@ -2615,6 +2671,14 @@
SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+ /* check the handle is still valid */
+ rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex);
+ if (rv == -1)
+ /* the handle is now invalid
+ * -> another thread may have called SCardReleaseContext
+ * -> so the mMutex has been unlocked */
+ return SCARD_E_INVALID_HANDLE;
+
for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
{
char *r = psContextMap[dwContextIndex].psChannelMap[dwChannelIndex].readerName;
@@ -2779,6 +2843,14 @@
SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+ /* check the handle is still valid */
+ rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex);
+ if (rv == -1)
+ /* the handle is now invalid
+ * -> another thread may have called SCardReleaseContext
+ * -> so the mMutex has been unlocked */
+ return SCARD_E_INVALID_HANDLE;
+
for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
{
char *r = psContextMap[dwContextIndex].psChannelMap[dwChannelIndex].readerName;
More information about the Pcsclite-cvs-commit
mailing list