[Pcsclite-muscle] [PATCH] fix racecondition between winscard server and clients

Florian Kaiser florian_kaiser
Wed Nov 30 04:26:11 PST 2016


Hi,

this change fixes a racecondition between a winscard server and clients.
Feel free to message me, if my explanation below is not sufficient. I will try 
to provide more Information in this case.


Regards,

Florian Kaiser


Signed-off-by: Florian Kaiser <florian_kaiser at genua.de>
---
 src/winscard_svc.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/src/winscard_svc.c b/src/winscard_svc.c
index b551c20..fc5ec38 100644
--- a/src/winscard_svc.c
+++ b/src/winscard_svc.c
@@ -419,10 +419,31 @@ static void ContextThread(LPVOID newContext)
 
                                READ_BODY(waStr)
 
-                               /* add the client fd to the list */
+                               /* remove the client fd from the list */
                                waStr.rv = EHUnregisterClientForEvent(filedes);
 
-                               WRITE_BODY(waStr)
+                               /* After the client timed out it sends a
+                                * CMD_STOP_WAITING_READER_STATE_CHANGE.
+                                * Sometimes an event occurs which triggers
+                                * MSGSignalClient, which unregisters the
+                                * client from events and sends a
+                                * wait_reader_state_change message to the
+                                * client. The client interprets this message
+                                * as an answer to its
+                                * CMD_STOP_WAITING_READER_STATE_CHANGE.
+                                * If we send another wait_reader_state_change
+                                * message to the client it stays in its buffer
+                                * until another Command is issued and this
+                                * message appears as leading garbage in the
+                                * commands answer.
+                                * Therefore we should not send the
+                                * wait_reader_state_change message here, if
+                                * the client has already been unregisterd 
from
+                                * events.
+                                */
+                               if (waStr.rv != SCARD_F_INTERNAL_ERROR) {
+                                       WRITE_BODY(waStr)
+                               }
                        }
                        break;
 
-- 
2.1.4




More information about the pcsclite-muscle mailing list