From 46e0c49d7bdf0aacda2abc6d88f0b6a18ecf1530 Mon Sep 17 00:00:00 2001 From: Martin Paljak Date: Thu, 16 Jun 2011 10:15:34 +0300 Subject: [PATCH] pcsc: correctly handle timeout situation when refreshing reader state. The code that treated a timeout as success was never reached, because the surrounding if eliminated the possibility of entering the block when the return code from SCardGetStatusChange was SCARD_E_TIMEOUT. Issue found by Coverity Scan. --- src/libopensc/reader-pcsc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libopensc/reader-pcsc.c b/src/libopensc/reader-pcsc.c index 0f5cb3c5..ab2f9733 100644 --- a/src/libopensc/reader-pcsc.c +++ b/src/libopensc/reader-pcsc.c @@ -286,8 +286,9 @@ static int refresh_attributes(sc_reader_t *reader) rv = priv->gpriv->SCardGetStatusChange(priv->gpriv->pcsc_ctx, 0, &priv->reader_state, 1); - if (rv != SCARD_S_SUCCESS && rv != (LONG)SCARD_E_TIMEOUT) { + if (rv != SCARD_S_SUCCESS) { if (rv == (LONG)SCARD_E_TIMEOUT) { + /* Timeout, no change from previous recorded state. Make sure that changed flag is not set. */ reader->flags &= ~SC_READER_CARD_CHANGED; SC_FUNC_RETURN(reader->ctx, SC_LOG_DEBUG_VERBOSE, SC_SUCCESS); }