Merge pull request #6757 from akallabeth/smart_e_invalid

Fix PCSC_SCardGetAttrib wrapper
This commit is contained in:
Martin Fleisz 2021-02-05 09:21:00 +01:00 committed by GitHub
commit 929fe163b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 23 deletions

View File

@ -3686,7 +3686,7 @@ static BOOL update_recv_secondary_order(rdpUpdate* update, wStream* s, BYTE flag
start = Stream_GetPosition(s); start = Stream_GetPosition(s);
name = secondary_order_string(orderType); name = secondary_order_string(orderType);
WLog_Print(update->log, WLOG_DEBUG, "Secondary Drawing Order %s", name); WLog_Print(update->log, WLOG_DEBUG, "Secondary Drawing Order %s", name);
rc = IFCALLRESULT(FALSE, secondary->CacheOrderInfo, context, orderLength, extraFlags, orderType, rc = IFCALLRESULT(TRUE, secondary->CacheOrderInfo, context, orderLength, extraFlags, orderType,
name); name);
if (!rc) if (!rc)
return FALSE; return FALSE;

View File

@ -2237,11 +2237,15 @@ static LONG WINAPI PCSC_SCardGetAttrib_Internal(SCARDHANDLE hCard, DWORD dwAttrI
if (!hContext) if (!hContext)
return SCARD_E_INVALID_HANDLE; return SCARD_E_INVALID_HANDLE;
if (!pbAttr || !pcbAttrLen) if (!pcbAttrLen)
return SCARD_E_INVALID_PARAMETER; return SCARD_E_INVALID_PARAMETER;
if (*pcbAttrLen == SCARD_AUTOALLOCATE) if (*pcbAttrLen == SCARD_AUTOALLOCATE)
{
if (!pbAttr)
return SCARD_E_INVALID_PARAMETER;
pcbAttrLenAlloc = TRUE; pcbAttrLenAlloc = TRUE;
}
pcsc_cbAttrLen = pcbAttrLenAlloc ? PCSC_SCARD_AUTOALLOCATE : (PCSC_DWORD)*pcbAttrLen; pcsc_cbAttrLen = pcbAttrLenAlloc ? PCSC_SCARD_AUTOALLOCATE : (PCSC_DWORD)*pcbAttrLen;
@ -2252,17 +2256,18 @@ static LONG WINAPI PCSC_SCardGetAttrib_Internal(SCARDHANDLE hCard, DWORD dwAttrI
if (status == SCARD_S_SUCCESS) if (status == SCARD_S_SUCCESS)
{ {
*conv.ppb = (BYTE*)calloc(1, pcsc_cbAttrLen); BYTE* tmp = (BYTE*)calloc(1, pcsc_cbAttrLen);
if (!*conv.ppb) if (!tmp)
return SCARD_E_NO_MEMORY; return SCARD_E_NO_MEMORY;
status = g_PCSC.pfnSCardGetAttrib(hCard, pcsc_dwAttrId, *conv.ppb, &pcsc_cbAttrLen); status = g_PCSC.pfnSCardGetAttrib(hCard, pcsc_dwAttrId, tmp, &pcsc_cbAttrLen);
if (status != SCARD_S_SUCCESS) if (status != SCARD_S_SUCCESS)
free(*conv.ppb); free(tmp);
else else
PCSC_AddMemoryBlock(hContext, *conv.ppb); PCSC_AddMemoryBlock(hContext, tmp);
*conv.ppb = tmp;
} }
} }
else else
@ -2298,6 +2303,8 @@ static LONG WINAPI PCSC_SCardGetAttrib_FriendlyName(SCARDHANDLE hCard, DWORD dwA
if (!hContext) if (!hContext)
return SCARD_E_INVALID_HANDLE; return SCARD_E_INVALID_HANDLE;
if (!pcbAttrLen)
return SCARD_E_INVALID_PARAMETER;
cbAttrLen = *pcbAttrLen; cbAttrLen = *pcbAttrLen;
*pcbAttrLen = SCARD_AUTOALLOCATE; *pcbAttrLen = SCARD_AUTOALLOCATE;
status = PCSC_SCardGetAttrib_Internal(hCard, SCARD_ATTR_DEVICE_FRIENDLY_NAME_A, status = PCSC_SCardGetAttrib_Internal(hCard, SCARD_ATTR_DEVICE_FRIENDLY_NAME_A,
@ -2407,12 +2414,18 @@ static LONG WINAPI PCSC_SCardGetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE
BYTE** ppb; BYTE** ppb;
} conv; } conv;
if (NULL == pcbAttrLen)
return SCARD_E_INVALID_PARAMETER;
conv.pb = pbAttr; conv.pb = pbAttr;
cbAttrLen = *pcbAttrLen; cbAttrLen = *pcbAttrLen;
if (*pcbAttrLen == SCARD_AUTOALLOCATE) if (*pcbAttrLen == SCARD_AUTOALLOCATE)
{ {
if (NULL == pbAttr)
return SCARD_E_INVALID_PARAMETER;
pcbAttrLenAlloc = TRUE; pcbAttrLenAlloc = TRUE;
*conv.ppb = NULL; *conv.ppb = NULL;
} }
@ -2444,22 +2457,25 @@ static LONG WINAPI PCSC_SCardGetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE
{ {
if (dwAttrId == SCARD_ATTR_VENDOR_NAME) if (dwAttrId == SCARD_ATTR_VENDOR_NAME)
{ {
const char* vendorName; if (pbAttr)
{
const char* vendorName;
/** /**
* pcsc-lite adds a null terminator to the vendor name, * pcsc-lite adds a null terminator to the vendor name,
* while WinSCard doesn't. Strip the null terminator. * while WinSCard doesn't. Strip the null terminator.
*/ */
if (pcbAttrLenAlloc) if (pcbAttrLenAlloc)
vendorName = (char*)*conv.ppb; vendorName = (char*)*conv.ppb;
else else
vendorName = (char*)pbAttr; vendorName = (char*)pbAttr;
if (vendorName) if (vendorName)
*pcbAttrLen = strlen(vendorName); *pcbAttrLen = strnlen(vendorName, *pcbAttrLen);
else else
*pcbAttrLen = 0; *pcbAttrLen = 0;
}
} }
} }
else else
@ -2852,7 +2868,9 @@ static LONG WINAPI PCSC_SCardGetDeviceTypeIdA(SCARDCONTEXT hContext, LPCSTR szRe
WINPR_UNUSED(hContext); WINPR_UNUSED(hContext);
WINPR_UNUSED(szReaderName); WINPR_UNUSED(szReaderName);
WINPR_UNUSED(pdwDeviceTypeId); WINPR_UNUSED(pdwDeviceTypeId);
return SCARD_E_UNSUPPORTED_FEATURE; if (pdwDeviceTypeId)
*pdwDeviceTypeId = SCARD_READER_TYPE_USB;
return SCARD_S_SUCCESS;
} }
static LONG WINAPI PCSC_SCardGetDeviceTypeIdW(SCARDCONTEXT hContext, LPCWSTR szReaderName, static LONG WINAPI PCSC_SCardGetDeviceTypeIdW(SCARDCONTEXT hContext, LPCWSTR szReaderName,
@ -2861,8 +2879,8 @@ static LONG WINAPI PCSC_SCardGetDeviceTypeIdW(SCARDCONTEXT hContext, LPCWSTR szR
WINPR_UNUSED(hContext); WINPR_UNUSED(hContext);
WINPR_UNUSED(szReaderName); WINPR_UNUSED(szReaderName);
if (pdwDeviceTypeId) if (pdwDeviceTypeId)
*pdwDeviceTypeId = 0; *pdwDeviceTypeId = SCARD_READER_TYPE_USB;
return SCARD_E_UNSUPPORTED_FEATURE; return SCARD_S_SUCCESS;
} }
static LONG WINAPI PCSC_SCardGetReaderDeviceInstanceIdA(SCARDCONTEXT hContext, LPCSTR szReaderName, static LONG WINAPI PCSC_SCardGetReaderDeviceInstanceIdA(SCARDCONTEXT hContext, LPCSTR szReaderName,