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"
This commit is contained in:
Ludovic Rousseau 2011-06-14 13:50:37 +02:00
parent 9ef95c71e6
commit 8936901e2b
1 changed files with 5 additions and 2 deletions

View File

@ -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 */