From 8936901e2b8fade5d9831b224f3313b7b3255133 Mon Sep 17 00:00:00 2001 From: Ludovic Rousseau Date: Tue, 14 Jun 2011 13:50:37 +0200 Subject: [PATCH] Correctly wait for card event The timeout parameter of SCardGetStatusChange() is a DWORD (unsigned int). An int timeout parameter was used instead. The problem happens on 64-bits architectures where DWORD is 64-bits long and int is only 32-bits long. The sign extension C mechanism transforms the PC/SC value INFINITE into -1 instead of 4294967295. See http://www.opensc-project.org/pipermail/opensc-devel/2011-June/016831.html "Kobil KAAN Advanced Reader, "waiting for card" timeout" --- src/libopensc/reader-pcsc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libopensc/reader-pcsc.c b/src/libopensc/reader-pcsc.c index 1071e045..a42df463 100644 --- a/src/libopensc/reader-pcsc.c +++ b/src/libopensc/reader-pcsc.c @@ -1029,6 +1029,7 @@ static int pcsc_wait_for_event(sc_context_t *ctx, unsigned int event_mask, sc_re size_t i; unsigned int num_watch; int r = SC_ERROR_INTERNAL; + DWORD dwtimeout; SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_NORMAL); @@ -1167,10 +1168,12 @@ static int pcsc_wait_for_event(sc_context_t *ctx, unsigned int event_mask, sc_re /* Set the timeout if caller wants to time out */ if (timeout == -1) { - timeout = INFINITE; + dwtimeout = INFINITE; } + else + dwtimeout = timeout; - rv = gpriv->SCardGetStatusChange(gpriv->pcsc_wait_ctx, timeout, rgReaderStates, num_watch); + rv = gpriv->SCardGetStatusChange(gpriv->pcsc_wait_ctx, dwtimeout, rgReaderStates, num_watch); if (rv == (LONG) SCARD_E_CANCELLED) { /* C_Finalize was called, events don't matter */