[Pcsclite-muscle] Crash in SCardStatus

Ludovic Rousseau ludovic.rousseau at gmail.com
Wed Dec 2 07:28:14 EST 2020


Le mar. 24 nov. 2020 à 13:28, Jonathan Verner
<jonathan.verner at nexusgroup.com> a écrit :
> Hello,

Hello Jonathan.

Sorry for the delay. Your email was in my gmail spam folder.

> I work for Nexus where we develop smartcard middleware and we use  libpcsc-lite. Recently, we have started seeing crashes on Linux (Ubuntu 18.04, which has libpcsc-lite version 1.8.23) when calling SCardStatus from our code. I suspect that the problem has to do with multiple threads calling into libpcsc-lite.
>
> In particular, the crash seems to happen when SCardStatus is called and, before it finishes, SCardDisconnect is called:
>
>    The crash happens in SCardStatus on line 1440 of winscard_clnt.c due to r (=pChannelMap->readerName)
>    no longer pointing to valid memory. My hypothesis is that, while calling getReaderStates on line 1434, a call to
>    SCardDisconnect arrives and frees the memory pointed to by pChannelMap->readerName.

Are you able to reproduce the problem with pcsc-lite version 1.9.0?
I ask because I fixed a race condition in SCardGetStatusChange() in
version 1.8.24
https://ludovicrousseau.blogspot.com/2018/10/new-version-of-pcsc-lite-1824.html

> On the other hand, I am quite new to pcsc and perhaps my analysis is incorrect (I am attaching the logs I get from pcscd and pcsc-spy if someone would be willing to look at them).  Anyway, I wanted to know, if there is some documentation on how to safely call libpcsc-lite functions from multiple threads.

For multiple threads be sure to read SCardEstablishContext() documentation
https://pcsclite.apdu.fr/api/group__API.html#gaa1b8970169fd4883a6dc4a8f43f19b67

Bye

-- 
 Dr. Ludovic Rousseau



More information about the pcsclite-muscle mailing list