From 64ff9ee1b6d7137718015a0e2b46e3d9c7f9213e Mon Sep 17 00:00:00 2001 From: Vincent Sourin Date: Tue, 9 Dec 2014 20:14:57 +0100 Subject: [PATCH] SmartCard * Check for NULL parameters in PCSC_ConvertReaderNameToWinSCard (Issue #2184) * Remove masking of dwEventState as it is not needed under Linux and MacOSX and it helps in ThinLinc environment * Workaround for Mac OS X Yosemite (10.10) SCardStatus Bug (Issue #2184) * Since Mac OS Tiger (10.5.6), Apple introduced new function for SCardControl calls named SCardControl132(), the old SCardControl doesn't work (cf. https://opensource.apple.com/source/SmartCardServices/SmartCardServices-55111/src/PCSC/winscard_clnt.c) --- winpr/libwinpr/smartcard/smartcard_pcsc.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/winpr/libwinpr/smartcard/smartcard_pcsc.c b/winpr/libwinpr/smartcard/smartcard_pcsc.c index cc694bea2..94f510868 100644 --- a/winpr/libwinpr/smartcard/smartcard_pcsc.c +++ b/winpr/libwinpr/smartcard/smartcard_pcsc.c @@ -644,6 +644,9 @@ char* PCSC_ConvertReaderNameToWinSCard(const char* name) * the index is a two digit zero-padded integer * the slot is a two digit zero-padded integer */ + if (!name) + return NULL; + length = strlen(name); if (length < 10) @@ -1476,8 +1479,6 @@ WINSCARDAPI LONG WINAPI PCSC_SCardGetStatusChange_Internal(SCARDCONTEXT hContext rgReaderStates[i].cbAtr = states[j].cbAtr; CopyMemory(&(rgReaderStates[i].rgbAtr), &(states[j].rgbAtr), PCSC_MAX_ATR_SIZE); - /* pcsc-lite puts an event count in the higher bits of dwEventState */ - states[j].dwEventState &= 0xFFFF; dwEventState = states[j].dwEventState & ~SCARD_STATE_CHANGED; if (dwEventState != rgReaderStates[i].dwCurrentState) @@ -1876,6 +1877,12 @@ WINSCARDAPI LONG WINAPI PCSC_SCardStatus_Internal(SCARDHANDLE hCard, { if (pcchReaderLenAlloc) { + /** + * Workaround for SCardStatus Bug in MAC OS X Yosemite + */ +#if defined (__APPLE__) && defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED == 1010 + pcsc_cchReaderLen++; +#endif *pMszReaderNames = (LPSTR) calloc(1, pcsc_cchReaderLen); if (!*pMszReaderNames) @@ -2702,7 +2709,11 @@ int PCSC_InitializeSCardApi(void) g_PCSC.pfnSCardEndTransaction = (void*) GetProcAddress(g_PCSCModule, "SCardEndTransaction"); g_PCSC.pfnSCardStatus = (void*) GetProcAddress(g_PCSCModule, "SCardStatus"); g_PCSC.pfnSCardGetStatusChange = (void*) GetProcAddress(g_PCSCModule, "SCardGetStatusChange"); +#if defined (__APPLE__) && defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1056 + g_PCSC.pfnSCardControl = (void*) GetProcAddress(g_PCSCModule, "SCardControl132"); +#else g_PCSC.pfnSCardControl = (void*) GetProcAddress(g_PCSCModule, "SCardControl"); +#endif g_PCSC.pfnSCardTransmit = (void*) GetProcAddress(g_PCSCModule, "SCardTransmit"); g_PCSC.pfnSCardListReaderGroups = (void*) GetProcAddress(g_PCSCModule, "SCardListReaderGroups"); g_PCSC.pfnSCardListReaders = (void*) GetProcAddress(g_PCSCModule, "SCardListReaders");