Fixed PCSC_SCardGetAttrib wrapper

This commit is contained in:
Armin Novak 2021-01-27 15:07:44 +01:00 committed by akallabeth
parent 1efcd605e0
commit 17d8267de7
2 changed files with 27 additions and 13 deletions

View File

@ -1866,7 +1866,7 @@ static LONG smartcard_GetAttrib_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPER
BOOL autoAllocate = FALSE;
LONG status;
DWORD cbAttrLen = 0;
LPBYTE* ppbAttr = NULL;
LPBYTE pbAttr = NULL;
GetAttrib_Return ret = { 0 };
IRP* irp = operation->irp;
const GetAttrib_Call* call = operation->call;
@ -1874,7 +1874,7 @@ static LONG smartcard_GetAttrib_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPER
if (!call->fpbAttrIsNULL)
{
autoAllocate = (call->cbAttrLen == SCARD_AUTOALLOCATE) ? TRUE : FALSE;
*ppbAttr = autoAllocate ? (LPBYTE) & (ret.pbAttr) : ret.pbAttr;
pbAttr = autoAllocate ? (LPBYTE) & (ret.pbAttr) : ret.pbAttr;
cbAttrLen = call->cbAttrLen;
}
@ -1886,8 +1886,7 @@ static LONG smartcard_GetAttrib_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPER
return SCARD_E_NO_MEMORY;
}
ret.ReturnCode = SCardGetAttrib(operation->hCard, call->dwAttrId, *ppbAttr, &cbAttrLen);
ret.ReturnCode = SCardGetAttrib(operation->hCard, call->dwAttrId, pbAttr, &cbAttrLen);
log_status_error(TAG, "SCardGetAttrib", ret.ReturnCode);
ret.cbAttrLen = cbAttrLen;

View File

@ -2237,11 +2237,15 @@ static LONG WINAPI PCSC_SCardGetAttrib_Internal(SCARDHANDLE hCard, DWORD dwAttrI
if (!hContext)
return SCARD_E_INVALID_HANDLE;
if (!pbAttr || !pcbAttrLen)
if (!pcbAttrLen)
return SCARD_E_INVALID_PARAMETER;
if (*pcbAttrLen == SCARD_AUTOALLOCATE)
{
if (!pbAttr)
return SCARD_E_INVALID_PARAMETER;
pcbAttrLenAlloc = TRUE;
}
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)
{
*conv.ppb = (BYTE*)calloc(1, pcsc_cbAttrLen);
BYTE* tmp = (BYTE*)calloc(1, pcsc_cbAttrLen);
if (!*conv.ppb)
if (!tmp)
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)
free(*conv.ppb);
free(tmp);
else
PCSC_AddMemoryBlock(hContext, *conv.ppb);
PCSC_AddMemoryBlock(hContext, tmp);
*conv.ppb = tmp;
}
}
else
@ -2298,6 +2303,8 @@ static LONG WINAPI PCSC_SCardGetAttrib_FriendlyName(SCARDHANDLE hCard, DWORD dwA
if (!hContext)
return SCARD_E_INVALID_HANDLE;
if (!pcbAttrLen)
return SCARD_E_INVALID_PARAMETER;
cbAttrLen = *pcbAttrLen;
*pcbAttrLen = SCARD_AUTOALLOCATE;
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;
} conv;
if (NULL == pcbAttrLen)
return SCARD_E_INVALID_PARAMETER;
conv.pb = pbAttr;
cbAttrLen = *pcbAttrLen;
if (*pcbAttrLen == SCARD_AUTOALLOCATE)
{
if (NULL == pbAttr)
return SCARD_E_INVALID_PARAMETER;
pcbAttrLenAlloc = TRUE;
*conv.ppb = NULL;
}
@ -2852,7 +2865,9 @@ static LONG WINAPI PCSC_SCardGetDeviceTypeIdA(SCARDCONTEXT hContext, LPCSTR szRe
WINPR_UNUSED(hContext);
WINPR_UNUSED(szReaderName);
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,
@ -2861,8 +2876,8 @@ static LONG WINAPI PCSC_SCardGetDeviceTypeIdW(SCARDCONTEXT hContext, LPCWSTR szR
WINPR_UNUSED(hContext);
WINPR_UNUSED(szReaderName);
if (pdwDeviceTypeId)
*pdwDeviceTypeId = 0;
return SCARD_E_UNSUPPORTED_FEATURE;
*pdwDeviceTypeId = SCARD_READER_TYPE_USB;
return SCARD_S_SUCCESS;
}
static LONG WINAPI PCSC_SCardGetReaderDeviceInstanceIdA(SCARDCONTEXT hContext, LPCSTR szReaderName,