diff --git a/channels/smartcard/client/smartcard_operations.c b/channels/smartcard/client/smartcard_operations.c index da86ff865..65f854120 100644 --- a/channels/smartcard/client/smartcard_operations.c +++ b/channels/smartcard/client/smartcard_operations.c @@ -421,7 +421,7 @@ static LONG smartcard_ListReaderGroupsW_Call(SMARTCARD_DEVICE* smartcard, status = ret.ReturnCode = SCardListReaderGroupsW(operation->hContext, (LPWSTR)&mszGroups, &cchGroups); ret.msz = (BYTE*)mszGroups; - ret.cBytes = cchGroups; + ret.cBytes = cchGroups * sizeof(WCHAR); if (status != SCARD_S_SUCCESS) return status; @@ -1719,6 +1719,9 @@ static LONG smartcard_StatusW_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERAT ret.cbAtrLen = cbAtrLen; } + /* SCardStatusW returns number of characters, we need number of bytes */ + ret.cBytes *= sizeof(WCHAR); + status = smartcard_pack_status_return(smartcard, irp->output, &ret, TRUE); if (status != SCARD_S_SUCCESS) return status; diff --git a/channels/smartcard/client/smartcard_pack.c b/channels/smartcard/client/smartcard_pack.c index fd88355f6..23a10cc45 100644 --- a/channels/smartcard/client/smartcard_pack.c +++ b/channels/smartcard/client/smartcard_pack.c @@ -2043,8 +2043,6 @@ LONG smartcard_pack_list_reader_groups_return(SMARTCARD_DEVICE* smartcard, wStre const ListReaderGroups_Return* ret, BOOL unicode) { DWORD index = 0; - UINT32 size = unicode ? sizeof(WCHAR) : sizeof(CHAR); - size *= ret->cBytes; smartcard_trace_list_reader_groups_return(smartcard, ret, unicode); if (ret->ReturnCode != SCARD_S_SUCCESS) @@ -2053,11 +2051,11 @@ LONG smartcard_pack_list_reader_groups_return(SMARTCARD_DEVICE* smartcard, wStre if (!Stream_EnsureRemainingCapacity(s, 4)) return SCARD_E_NO_MEMORY; - Stream_Write_UINT32(s, size); /* cBytes (4 bytes) */ - if (!smartcard_ndr_pointer_write(s, &index, size)) + Stream_Write_UINT32(s, ret->cBytes); /* cBytes (4 bytes) */ + if (!smartcard_ndr_pointer_write(s, &index, ret->cBytes)) return SCARD_E_NO_MEMORY; - return smartcard_ndr_write(s, ret->msz, size, 1, NDR_PTR_SIMPLE); + return smartcard_ndr_write(s, ret->msz, ret->cBytes, 1, NDR_PTR_SIMPLE); } LONG smartcard_unpack_list_readers_call(SMARTCARD_DEVICE* smartcard, wStream* s, @@ -2658,8 +2656,6 @@ LONG smartcard_pack_status_return(SMARTCARD_DEVICE* smartcard, wStream* s, const BOOL unicode) { DWORD index = 0; - UINT32 size = unicode ? sizeof(WCHAR) : sizeof(CHAR); - size *= ret->cBytes; smartcard_trace_status_return(smartcard, ret, unicode); if (ret->ReturnCode != SCARD_S_SUCCESS) @@ -2668,8 +2664,8 @@ LONG smartcard_pack_status_return(SMARTCARD_DEVICE* smartcard, wStream* s, const if (!Stream_EnsureRemainingCapacity(s, 4)) return SCARD_F_INTERNAL_ERROR; - Stream_Write_UINT32(s, size); /* cBytes (4 bytes) */ - if (!smartcard_ndr_pointer_write(s, &index, size)) + Stream_Write_UINT32(s, ret->cBytes); /* cBytes (4 bytes) */ + if (!smartcard_ndr_pointer_write(s, &index, ret->cBytes)) return SCARD_E_NO_MEMORY; if (!Stream_EnsureRemainingCapacity(s, 44)) @@ -2679,7 +2675,7 @@ LONG smartcard_pack_status_return(SMARTCARD_DEVICE* smartcard, wStream* s, const Stream_Write_UINT32(s, ret->dwProtocol); /* dwProtocol (4 bytes) */ Stream_Write(s, ret->pbAtr, sizeof(ret->pbAtr)); /* pbAtr (32 bytes) */ Stream_Write_UINT32(s, ret->cbAtrLen); /* cbAtrLen (4 bytes) */ - return smartcard_ndr_write(s, ret->mszReaderNames, size, 1, NDR_PTR_SIMPLE); + return smartcard_ndr_write(s, ret->mszReaderNames, ret->cBytes, 1, NDR_PTR_SIMPLE); } LONG smartcard_unpack_get_attrib_call(SMARTCARD_DEVICE* smartcard, wStream* s, GetAttrib_Call* call)