[Pcsclite-cvs-commit] r2960 - /trunk/PCSC/src/winscard_clnt.c

rousseau at users.alioth.debian.org rousseau at users.alioth.debian.org
Fri May 16 09:03:48 UTC 2008


Author: rousseau
Date: Fri May 16 09:03:48 2008
New Revision: 2960

URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=2960
Log:
SCardReleaseContext(), SCardConnect(), SCardGetStatusChange(),
SCardListReaders() and SCardListReaderGroups: check that the context is
still opened 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=2960&op=diff
==============================================================================
--- trunk/PCSC/src/winscard_clnt.c (original)
+++ trunk/PCSC/src/winscard_clnt.c Fri May 16 09:03:48 2008
@@ -593,6 +593,14 @@
 	}
 
 	SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+
+	/* check the context is still opened */
+	dwContextIndex = SCardGetContextIndice(hContext); 	 
+	if (dwContextIndex == -1)
+		/* the context is now invalid
+		 * -> another thread may have called SCardReleaseContext
+		 * -> so the mMutex has been unlocked */
+		return SCARD_E_INVALID_HANDLE;
 
 	scReleaseStruct.hContext = hContext;
 	scReleaseStruct.rv = SCARD_S_SUCCESS;
@@ -749,6 +757,14 @@
 		return SCARD_E_INVALID_HANDLE;
 
 	SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+
+	/* check the context is still opened */
+	dwContextIndex = SCardGetContextIndice(hContext); 	 
+	if (dwContextIndex == -1)
+		/* the context is now invalid
+		 * -> another thread may have called SCardReleaseContext
+		 * -> so the mMutex has been unlocked */
+		return SCARD_E_INVALID_HANDLE;
 
 	strncpy(scConnectStruct.szReader, szReader, MAX_READERNAME);
 
@@ -1701,6 +1717,14 @@
 		return SCARD_E_INVALID_HANDLE;
 
 	SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+
+	/* check the context is still opened */
+	dwContextIndex = SCardGetContextIndice(hContext); 	 
+	if (dwContextIndex == -1)
+		/* the context is now invalid
+		 * -> another thread may have called SCardReleaseContext
+		 * -> so the mMutex has been unlocked */
+		return SCARD_E_INVALID_HANDLE;
 
 	/*
 	 * Application is waiting for a reader - return the first available
@@ -3019,6 +3043,14 @@
 
 	SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
 
+	/* check the context is still opened */
+	dwContextIndex = SCardGetContextIndice(hContext); 	 
+	if (dwContextIndex == -1)
+		/* the context is now invalid
+		 * -> another thread may have called SCardReleaseContext
+		 * -> so the mMutex has been unlocked */
+		return SCARD_E_INVALID_HANDLE;
+
 	dwReadersLen = 0;
 	for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
 		if ((readerStates[i])->readerID != 0)
@@ -3125,6 +3157,14 @@
 		return SCARD_E_INVALID_HANDLE;
 
 	SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+
+	/* check the context is still opened */
+	dwContextIndex = SCardGetContextIndice(hContext); 	 
+	if (dwContextIndex == -1)
+		/* the context is now invalid
+		 * -> another thread may have called SCardReleaseContext
+		 * -> so the mMutex has been unlocked */
+		return SCARD_E_INVALID_HANDLE;
 
 	if (mszGroups)
 	{




More information about the Pcsclite-cvs-commit mailing list