[Pcsclite-muscle] [PATCH] EHUnregisterClientForEvent() Can't remove client

Vadim V. Vlasov vvlasov at dev.rtsoft.ru
Thu Apr 21 15:03:18 UTC 2016


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
CMD_WAIT_READER_STATE_CHANGE
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
CMD_STOP_WAITING_READER_STATE_CHANGE
7. Client reads the "reply" which is actually sent in step 5, and
continues.
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
client.."
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.

---
 src/winscard_svc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/winscard_svc.c b/src/winscard_svc.c
index b551c20..318bb74 100644
--- a/src/winscard_svc.c
+++ b/src/winscard_svc.c
@@ -422,7 +422,10 @@ static void ContextThread(LPVOID newContext)
                                /* add the client fd to the list */
                                waStr.rv =
EHUnregisterClientForEvent(filedes);
 
-                               WRITE_BODY(waStr)
+                               if (waStr.rv == SCARD_S_SUCCESS)
+                               {
+                                       WRITE_BODY(waStr)
+                               }
                        }
                        break;
 
-- 
1.9.3





More information about the Pcsclite-muscle mailing list