[Pcsclite-git-commit] [PCSC] 08/11: SCardCancel was not correctly handled

Ludovic Rousseau rousseau at moszumanska.debian.org
Fri Mar 11 17:54:48 UTC 2016


This is an automated email from the git hooks/post-receive script.

rousseau pushed a commit to branch master
in repository PCSC.

commit 57b0ba5a200bcbf1c489d39261340324392a8e8a
Author: Ludovic Rousseau <ludovic.rousseau at free.fr>
Date:   Fri Mar 11 11:40:09 2016 +0100

    SCardCancel was not correctly handled
    
    When a SCardGetStatusChange() was cancelled then a next PC/SC call
    after the SCardGetStatusChange() may fail with a strange error code if
    the event waited in SCardGetStatusChange() occurs.
    
    " Looks like there is a bug related to the management of the blocking
    requests and of their cancellation.
    
    The reproduce steps are the following. Two threads: thread 1 and
    thread 2. Thread 2 calls SCardGetStatusChange and blocks (with waiting
    for some event X). Thread 1 calls SCardCancel. Thread 2 unblocks from
    SCardGetStatusChange due to the cancellation, and starts issuing other
    PC/SC-Lite API calls. After that, something that triggers the event X
    happens. After that the PC/SC-Lite API calls that thread 2 is making
    start to break (they return inconsistent results).
    
    The underlying reason is that cancellation in the current
    implementation of the PC/SC-Lite service does not unsubscribe the
    client from the list of clients waiting for events. So, when the event
    finally occurs, the event response is written into the client's
    socket, even if the cancellation had already happened before. Putting
    unexpected data into the socket shifts the responses of all further
    PC/SC-Lite API calls made by that client.
    
    If the analysis above is correct, then the correct fix would be
    probably just adding a "EHTryToUnregisterClientForEvent(fd)" statement
    into the handler of the SCARD_CANCEL message in function ContextThread
    (file winscard_svc.c). "
    
    Thanks to Maksim Ivanov for the bug report and patch
    http://lists.alioth.debian.org/pipermail/pcsclite-muscle/Week-of-Mon-20160307/000538.html
---
 src/winscard_svc.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/winscard_svc.c b/src/winscard_svc.c
index 75e4c8e..b551c20 100644
--- a/src/winscard_svc.c
+++ b/src/winscard_svc.c
@@ -580,6 +580,10 @@ static void ContextThread(LPVOID newContext)
 				{
 					uint32_t fd = psTargetContext->dwClientID;
 					caStr.rv = MSGSignalClient(fd, SCARD_E_CANCELLED);
+
+					/* the client should not receive the event
+					 * notification now the waiting has been cancelled */
+					EHUnregisterClientForEvent(fd);
 				}
 				else
 					caStr.rv = SCARD_E_INVALID_HANDLE;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pcsclite/PCSC.git



More information about the Pcsclite-cvs-commit mailing list