Fixed issue with GetAttr where the result buffer was not allocated

This commit is contained in:
akallabeth
2021-02-07 18:48:59 +01:00
committed by akallabeth
parent 14d5ad0d79
commit bad20340cc
4 changed files with 20 additions and 17 deletions

View File

@@ -1813,23 +1813,24 @@ static LONG smartcard_GetAttrib_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPER
if (!call->fpbAttrIsNULL)
{
autoAllocate = (call->cbAttrLen == SCARD_AUTOALLOCATE) ? TRUE : FALSE;
pbAttr = autoAllocate ? (LPBYTE) & (ret.pbAttr) : ret.pbAttr;
cbAttrLen = call->cbAttrLen;
}
if (cbAttrLen && !autoAllocate)
{
ret.pbAttr = (BYTE*)malloc(cbAttrLen);
if (cbAttrLen && !autoAllocate)
{
ret.pbAttr = (BYTE*)malloc(cbAttrLen);
if (!ret.pbAttr)
return SCARD_E_NO_MEMORY;
}
if (!ret.pbAttr)
return SCARD_E_NO_MEMORY;
pbAttr = autoAllocate ? (LPBYTE) & (ret.pbAttr) : ret.pbAttr;
}
ret.ReturnCode = SCardGetAttrib(operation->hCard, call->dwAttrId, pbAttr, &cbAttrLen);
log_status_error(TAG, "SCardGetAttrib", ret.ReturnCode);
ret.cbAttrLen = cbAttrLen;
status = smartcard_pack_get_attrib_return(smartcard, irp->output, &ret, call->dwAttrId);
status = smartcard_pack_get_attrib_return(smartcard, irp->output, &ret, call->dwAttrId,
call->cbAttrLen);
if (autoAllocate)
SCardFreeMemory(operation->hContext, ret.pbAttr);

View File

@@ -2791,7 +2791,8 @@ LONG smartcard_unpack_get_attrib_call(SMARTCARD_DEVICE* smartcard, wStream* s, G
}
LONG smartcard_pack_get_attrib_return(SMARTCARD_DEVICE* smartcard, wStream* s,
const GetAttrib_Return* ret, DWORD dwAttrId)
const GetAttrib_Return* ret, DWORD dwAttrId,
DWORD cbAttrCallLen)
{
LONG status;
DWORD cbAttrLen;
@@ -2802,10 +2803,12 @@ LONG smartcard_pack_get_attrib_return(SMARTCARD_DEVICE* smartcard, wStream* s,
return SCARD_F_INTERNAL_ERROR;
cbAttrLen = ret->cbAttrLen;
if (ret->ReturnCode == SCARD_E_INSUFFICIENT_BUFFER)
if (ret->ReturnCode != SCARD_S_SUCCESS)
cbAttrLen = 0;
if (cbAttrLen == SCARD_AUTOALLOCATE)
cbAttrLen = 0;
if (cbAttrCallLen < cbAttrLen)
cbAttrLen = cbAttrCallLen;
Stream_Write_UINT32(s, cbAttrLen); /* cbAttrLen (4 bytes) */
if (!smartcard_ndr_pointer_write(s, &index, cbAttrLen))
return SCARD_E_NO_MEMORY;

View File

@@ -140,7 +140,8 @@ LONG smartcard_unpack_get_attrib_call(SMARTCARD_DEVICE* smartcard, wStream* s,
GetAttrib_Call* call);
LONG smartcard_pack_get_attrib_return(SMARTCARD_DEVICE* smartcard, wStream* s,
const GetAttrib_Return* ret, DWORD dwAttrId);
const GetAttrib_Return* ret, DWORD dwAttrId,
DWORD cbAttrCallLen);
LONG smartcard_unpack_set_attrib_call(SMARTCARD_DEVICE* smartcard, wStream* s,
SetAttrib_Call* call);