There is a race between client waiting for the reader status change
and the server. Consider the following sequence of events:
1. Client calls SCardGetStatusChange() which sends
to the server.
2. Client waits with timeout for the reply.
3. MessageReceiveTimeout() returns with timeout.
4. The waited for event is detected by the server.
5. The server (pcscd) sends 'SIGNAL' to the client (and removes it from
the ClientsWaitingForEvent list.
6. Client continues execution and sends
7. Client reads the "reply" which is actually sent in step 5, and
8. Server receives CMD_STOP_WAITING_READER_STATE_CHANGE, attempts to
remove the client from the list (ClientsWaitingForEvent) but fails.
9. Server reports "...EHUnregisterClientForEvent() Can't remove
error into the log and replies (with error) to the client.
After that client's input socket contains an extra message which is not
expected by the client but would be read later instead of next server's
response. So, the client-server communication is desinchronized.
The patch avoids sending reply to CMD_STOP_WAITING_READER_STATE_CHANGE
if the client is not found in the ClientsWaitingForEvent list.