<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2016-03-10 20:01 GMT+01:00 Maksim Ivanov <span dir="ltr"><<a href="mailto:emaxx@google.com" target="_blank">emaxx@google.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello all,<br></blockquote><div><br></div><div>Hello Maksim,<br> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Looks like there is a bug related to the management of the blocking<br>
requests and of their cancellation.<br>
<br>
The reproduce steps are the following. Two threads: thread 1 and<br>
thread 2. Thread 2 calls SCardGetStatusChange and blocks (with waiting<br>
for some event X). Thread 1 calls SCardCancel. Thread 2 unblocks from<br>
SCardGetStatusChange due to the cancellation, and starts issuing other<br>
PC/SC-Lite API calls. After that, something that triggers the event X<br>
happens. After that the PC/SC-Lite API calls that thread 2 is making<br>
start to break (they return inconsistent results).<br>
<br>
The underlying reason is that cancellation in the current<br>
implementation of the PC/SC-Lite service does not unsubscribe the<br>
client from the list of clients waiting for events. So, when the event<br>
finally occurs, the event response is written into the client's<br>
socket, even if the cancellation had already happened before. Putting<br>
unexpected data into the socket shifts the responses of all further<br>
PC/SC-Lite API calls made by that client.<br>
<br>
If the analysis above is correct, then the correct fix would be<br>
probably just adding a "EHTryToUnregisterClientForEvent(fd)" statement<br>
into the handler of the SCARD_CANCEL message in function ContextThread<br>
(file winscard_svc.c).<br></blockquote><div><br></div><div>You are right.<br><br></div><div>Fixed in 57b0ba5a200bcbf1c489d39261340324392a8e8a<br></div><br></div><div class="gmail_quote">Thanks for the analysis and proposed patch.<br><br></div><div class="gmail_quote">Please tell me when you have finished your code review so I can publish a new version of pcsc-lite with all the fixes :-)<br><br></div><div class="gmail_quote">Bye<br></div><div class="gmail_quote"><br></div>-- <br><div class="gmail_signature"> Dr. Ludovic Rousseau</div>
</div></div>